|
|
|
@ -7,7 +7,6 @@ TEST_CASE("Check http status"){ |
|
|
|
auto out=http::code(http::ok); |
|
|
|
auto out=http::code(http::ok); |
|
|
|
REQUIRE(out.first == 200); |
|
|
|
REQUIRE(out.first == 200); |
|
|
|
REQUIRE(out.second == "OK"); |
|
|
|
REQUIRE(out.second == "OK"); |
|
|
|
// TODO test all
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
SCENARIO("http response"){ |
|
|
|
SCENARIO("http response"){ |
|
|
|
@ -63,55 +62,3 @@ SCENARIO("Stream http responses with a json response"){ |
|
|
|
REQUIRE(ss.str()=="HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: 2\r\n\r\n{}"s); |
|
|
|
REQUIRE(ss.str()=="HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: 2\r\n\r\n{}"s); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
TEST(http_response_handler, header){ |
|
|
|
|
|
|
|
ServerTest s; |
|
|
|
|
|
|
|
auto req=s.create_request("GET /v1/session/torrents HTTP/1.1\r\nHost: localhost:8080\r\nFoo: bar\r\nFoo: bars\r\nContent-Type: application/json\r\n\r\n"); |
|
|
|
|
|
|
|
std::shared_ptr<ServerTest::Response> resp(new ServerTest::Response(nullptr)); |
|
|
|
|
|
|
|
http::request_handler out(req,resp); |
|
|
|
|
|
|
|
ASSERT_TRUE(out.header_set("Content-Type")); |
|
|
|
|
|
|
|
ASSERT_EQ(out.find_last_header_value("Content-Type"),"application/json"); |
|
|
|
|
|
|
|
ASSERT_EQ(out.find_last_header_value("Host"),"localhost:8080"); |
|
|
|
|
|
|
|
ASSERT_EQ(out.find_last_header_value("Foo"),"bars"); |
|
|
|
|
|
|
|
ASSERT_NE(out.find_last_header_value("Foo"), "bar"); |
|
|
|
|
|
|
|
ASSERT_FALSE(out.header_set("Content-Length")); |
|
|
|
|
|
|
|
ASSERT_TRUE(out.header_equals("Content-Type","application/json")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST(http_response_handler, json_response){ |
|
|
|
|
|
|
|
ServerTest s; |
|
|
|
|
|
|
|
auto req=s.create_request("GET /v1/session/torrents HTTP/1.1\r\nHost: localhost:8080\r\nContent-Type: application/json\r\n\r\n"); |
|
|
|
|
|
|
|
std::shared_ptr<ServerTest::Response> resp(new ServerTest::Response(nullptr)); |
|
|
|
|
|
|
|
http::request_handler out(req,resp); |
|
|
|
|
|
|
|
out.respond(nlohmann::json("{}")); |
|
|
|
|
|
|
|
std::stringstream ss; |
|
|
|
|
|
|
|
ss << resp->rdbuf(); |
|
|
|
|
|
|
|
std::string string_response(ss.str()); |
|
|
|
|
|
|
|
ASSERT_EQ(string_response,"HTTP/1.1 200 OK\r\nContent-Length: 4\r\nContent-Type: application/json\r\n\r\n\"{}\""); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST(http_response_handler, string_response){ |
|
|
|
|
|
|
|
ServerTest s; |
|
|
|
|
|
|
|
auto req=s.create_request("GET /v1/session/torrents HTTP/1.1\r\nHost: localhost:8080\r\nContent-Type: application/json\r\n\r\n"); |
|
|
|
|
|
|
|
std::shared_ptr<ServerTest::Response> resp(new ServerTest::Response(nullptr)); |
|
|
|
|
|
|
|
http::request_handler out(req,resp); |
|
|
|
|
|
|
|
out.respond(std::string("{}")); |
|
|
|
|
|
|
|
std::stringstream ss; |
|
|
|
|
|
|
|
ss << resp->rdbuf(); |
|
|
|
|
|
|
|
std::string string_response(ss.str()); |
|
|
|
|
|
|
|
ASSERT_EQ(string_response,"HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\n{}"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST(http_response_handler, empty_string){ |
|
|
|
|
|
|
|
ServerTest s; |
|
|
|
|
|
|
|
auto req=s.create_request("GET /v1/session/torrents HTTP/1.1\r\nHost: localhost:8080\r\nContent-Type: application/json\r\n\r\n"); |
|
|
|
|
|
|
|
std::shared_ptr<ServerTest::Response> resp(new ServerTest::Response(nullptr)); |
|
|
|
|
|
|
|
http::request_handler out(req,resp); |
|
|
|
|
|
|
|
out.respond(std::string("")); |
|
|
|
|
|
|
|
std::stringstream ss; |
|
|
|
|
|
|
|
ss << resp->rdbuf(); |
|
|
|
|
|
|
|
std::string string_response(ss.str()); |
|
|
|
|
|
|
|
ASSERT_EQ(string_response,"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
*/ |
|
|
|
|