From 40abb49483df0feb52382485bf3c66d81b25f08b Mon Sep 17 00:00:00 2001 From: Peter Thorson Date: Sun, 3 Mar 2013 17:34:53 -0600 Subject: [PATCH] adds tests related to request bodies --- test/http/parser.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/test/http/parser.cpp b/test/http/parser.cpp index 4fef23826b..f16ff3c560 100644 --- a/test/http/parser.cpp +++ b/test/http/parser.cpp @@ -828,3 +828,44 @@ BOOST_AUTO_TEST_CASE( plain_http_response ) { BOOST_CHECK( r.get_header("Content-Type") == "text/html" ); BOOST_CHECK( r.get_body() == "\n\n\nThor\n\n \n

Thor

\n" ); } + +BOOST_AUTO_TEST_CASE( write_request_basic ) { + websocketpp::http::parser::request r; + + std::string raw = "GET / HTTP/1.1\r\n\r\n"; + + r.set_version("HTTP/1.1"); + r.set_method("GET"); + r.set_uri("/"); + + BOOST_CHECK( r.raw() == raw ); +} + +BOOST_AUTO_TEST_CASE( write_request_with_header ) { + websocketpp::http::parser::request r; + + std::string raw = "GET / HTTP/1.1\r\nHost: http://example.com\r\n\r\n"; + + r.set_version("HTTP/1.1"); + r.set_method("GET"); + r.set_uri("/"); + r.replace_header("Host","http://example.com"); + + BOOST_CHECK( r.raw() == raw ); +} + +BOOST_AUTO_TEST_CASE( write_request_with_body ) { + websocketpp::http::parser::request r; + + std::string raw = "POST / HTTP/1.1\r\nContent-Length: 48\r\nContent-Type: application/x-www-form-urlencoded\r\nHost: http://example.com\r\n\r\nlicenseID=string&content=string¶msXML=string"; + + r.set_version("HTTP/1.1"); + r.set_method("POST"); + r.set_uri("/"); + r.replace_header("Host","http://example.com"); + r.replace_header("Content-Type","application/x-www-form-urlencoded"); + r.set_body("licenseID=string&content=string¶msXML=string"); + + std::cout << r.raw() << std::endl; + BOOST_CHECK( r.raw() == raw ); +} \ No newline at end of file