\n"; + ss << "\n"; + ss << "Error " << status << " " << reason << "
\n"; + ss << "
\n"; + ss << "Our apologies for the temporary inconvenience. The requested URL was not found on this server.\n
" + "
Our apologies for the temporary inconvenience. The requested URL was not found on this server.\n
")); +} + +TEST(E2E, duplicate_host_header) { + std::string host = "localhost"; + std::string port = "80"; + std::string method = "GET"; + std::string path = "/cgi-bin/"; + std::string body = "hello"; + std::string headers = "Host: localhost;Host: localhost"; + std::string res = sendInvalidRequest(host, port, method, path, body, headers); + std::cerr << res << std::endl; + // ASSERT_TRUE(includes(res, "HTTP/1.1 200 OK")); + ASSERT_TRUE(includes(res, "HTTP/1.1 400 Bad Request")); + ASSERT_TRUE(includes( + res, "Our apologies for the temporary inconvenience. The requested URL was not found on this server.\n
")); +} + TEST(E2E, Chunked) { std::string host = "localhost"; std::string port = "80"; @@ -149,7 +200,7 @@ TEST(E2E, Chunked) { std::string headers = "Host: localhost;Transfer-Encoding:chunked, chunked , chunked "; std::string res = sendRequest(host, port, method, path, body, headers); - + std::cerr << res << std::endl; // ASSERT_TRUE(includes(res, "HTTP/1.1 200 OK")); ASSERT_TRUE(includes(res, "")); } @@ -164,7 +215,7 @@ TEST(E2E, ObsFold) { std::string res = sendRequest(host, port, method, path, body, headers); - std::cout << res << std::endl; + std::cerr << res << std::endl; EXPECT_TRUE(includes(res, "HTTP/1.1 400 Bad Request")); } @@ -238,3 +289,67 @@ std::string sendRequest(const std::string &host, const std::string &port, const return response; } + +std::string sendInvalidRequest(const std::string &host, const std::string &port, const std::string &method, + const std::string &path, const std::string &body, const std::string &headers) { + struct addrinfo hints, *res; + int err; + int sock; + + memset(&hints, 0, sizeof(hints)); + hints.ai_socktype = SOCK_STREAM; + // 名前解決の方法を指定 + hints.ai_family = AF_INET; + + if ((err = getaddrinfo(host.c_str(), port.c_str(), &hints, &res)) != 0) { + return ""; + } + void *ptr = &((struct sockaddr_in *)res->ai_addr)->sin_addr; + char addr_buf[64]; + inet_ntop(res->ai_family, ptr, addr_buf, sizeof(addr_buf)); + + sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol); + if (sock == -1) { + perror("socket"); + return ""; + } + + if (connect(sock, res->ai_addr, res->ai_addrlen) == -1) { + perror("connect"); + return ""; + } + std::stringstream ss; + ss << method << " " << path << " " + << "HTTP/1.1\r\n"; + std::vector