Exemplo n.º 1
0
TEST(HTTPRequestParser, WellFormedRequestLineOnly) {
    HTTPRequestParser http_request_parser("GET / HTTP/1.1\r\n\r\n");
    HTTPRequest* http_request = Object::cast<HTTPRequest>(http_request_parser.parse());
    ASSERT_NE(http_request, static_cast<Object*>(NULL));
    ASSERT_EQ(http_request->get_method(), HTTPRequest::Method::GET);
    ASSERT_EQ(http_request->get_http_version(), 1);
    ASSERT_EQ(http_request->get_body(), static_cast<Object*>(NULL));
    HTTPRequest::dec_ref(http_request);
}
Exemplo n.º 2
0
void http(
	struct sockaddr_in server_addr,
	struct tcp_config tcp_config,
	void (*tcp_processor)(char*)
) {
	struct sockaddr_in client_address;
	int server_sockfd, client_sockfd;
	int client_len;
	int server_len;

	int tcp_domain = AF_INET;
	int tcp_type = SOCK_STREAM;
	int tcp_protocol = 0;

	server_address.sin_family = AF_INET;
	server_address.sin_port = htons(port);
	server_address.sin_addr.s_addr = inet_addr("127.0.0.1");
	server_len = sizeof(server_address);

	unlink("server_socket");
	server_sockfd = socket(
		tcp_config.domain,
		tcp_config.type,
		tcp_config.protocol
	);

	bind(
		server_sockfd,
		(struct sockaddr *)&server_address,
		sizeof(server_addr)
	);

	listen(server_sockfd, 5);
	printf("server listening on port %d.\n", port);

	char ch;
	client_len = sizeof(client_address);
	client_sockfd = accept(
		server_sockfd,
		(struct sockaddr *)&client_address,
		&client_len
	);

	while (1)
	{
		read(client_sockfd, ch, 1);
		http_request_parser(ch);
	}

	write(client_sockfd, &ch, 1);

	close(client_sockfd);

	
}
Exemplo n.º 3
0
TEST(HTTPRequestParser, MalformedURIMissing) {
    HTTPRequestParser http_request_parser("GET HTTP/1.1\r\nHost: localhost\r\n\r\n");
    HTTPRequest* http_request = Object::cast<HTTPRequest>(http_request_parser.parse());
    ASSERT_EQ(http_request, static_cast<Object*>(NULL));
}
Exemplo n.º 4
0
TEST(HTTPRequestParser, MalformedHTTPVersionMissingTrailingCRLF) {
    HTTPRequestParser http_request_parser("GET / HTTP/1.1Host: localhost\r\n\r\n");
    HTTPRequest* http_request = Object::cast<HTTPRequest>(http_request_parser.parse());
    ASSERT_EQ(http_request, static_cast<Object*>(NULL));
}
Exemplo n.º 5
0
TEST(HttpRequestParser, MalformedURIEmbeddedLF) {
  HttpRequestParser http_request_parser("GET /\r HTTP/1.1\r\nHost: localhost\r\n\r\n");
  HttpRequest* http_request = Object::cast<HttpRequest>(http_request_parser.parse());
  ASSERT_EQ(http_request, static_cast<Object*>(NULL));
}
Exemplo n.º 6
0
TEST(HttpRequestParser, MalformedMethodMissing) {
  HttpRequestParser http_request_parser("/ HTTP/1.0\r\nHost: localhost\r\n\r\n");
  HttpRequest* http_request = Object::cast<HttpRequest>(http_request_parser.parse());
  ASSERT_EQ(http_request, static_cast<Object*>(NULL));
}
Exemplo n.º 7
0
TEST(HttpRequestParser, MalformedHTTPVersionMissingMinorVersion) {
  HttpRequestParser http_request_parser("GET / HTTP/1.\r\nHost: localhost\r\n\r\n");
  HttpRequest* http_request = Object::cast<HttpRequest>(http_request_parser.parse());
  ASSERT_EQ(http_request, static_cast<Object*>(NULL));
}