127 std::string
d1 =
"\"foo\"";
128 std::string d2 =
"\"foo\\\"bar\\\"baz\"";
129 std::string d3 =
"\"foo\" ";
131 std::string d5 =
"foo";
133 std::pair<std::string,std::string::const_iterator>
ret;
137 ret = extract_quoted_string(
d1.begin(),
d1.end());
138 BOOST_CHECK(
ret.first ==
"foo" );
139 BOOST_CHECK(
ret.second ==
d1.end() );
141 ret = extract_quoted_string(d2.begin(),d2.end());
142 BOOST_CHECK(
ret.first ==
"foo\"bar\"baz" );
143 BOOST_CHECK(
ret.second == d2.end() );
145 ret = extract_quoted_string(d3.begin(),d3.end());
146 BOOST_CHECK(
ret.first ==
"foo" );
147 BOOST_CHECK(
ret.second == d3.begin()+5 );
149 ret = extract_quoted_string(d4.begin(),d4.end());
150 BOOST_CHECK(
ret.first.empty() );
151 BOOST_CHECK(
ret.second == d4.begin() );
153 ret = extract_quoted_string(d5.begin(),d5.end());
154 BOOST_CHECK(
ret.first.empty() );
155 BOOST_CHECK(
ret.second == d5.begin() );
213 std::string s2 =
"foo";
214 std::string s3 =
" foo \r\nAbc";
215 std::string s4 =
" \r\n foo ";
216 std::string s5 =
"foo,bar";
217 std::string s6 =
"foo;bar";
218 std::string s7 =
"foo;baz,bar";
219 std::string s8 =
"foo;bar;baz";
220 std::string s9 =
"foo;bar=baz";
221 std::string s10 =
"foo;bar=baz;boo";
222 std::string s11 =
"foo;bar=baz;boo,bob";
223 std::string s12 =
"foo;bar=\"a b c\"";
224 std::string s13 =
"foo;bar=\"a \\\"b\\\" c\"";
227 std::string sx =
"foo;bar=\"a \\\"b\\\" c\"";
230 std::string::const_iterator it;
234 it = extract_parameters(s1.begin(),s1.end(),
p);
235 BOOST_CHECK( it == s1.begin() );
238 it = extract_parameters(s2.begin(),s2.end(),
p);
239 BOOST_CHECK( it == s2.end() );
240 BOOST_CHECK_EQUAL(
p.
size(), 1 );
241 BOOST_CHECK(
p[0].first ==
"foo" );
242 BOOST_CHECK_EQUAL(
p[0].second.
size(), 0 );
245 it = extract_parameters(s3.begin(),s3.end(),
p);
246 BOOST_CHECK( it == s3.begin()+5 );
247 BOOST_CHECK_EQUAL(
p.
size(), 1 );
248 BOOST_CHECK(
p[0].first ==
"foo" );
249 BOOST_CHECK_EQUAL(
p[0].second.
size(), 0 );
252 it = extract_parameters(s4.begin(),s4.end(),
p);
253 BOOST_CHECK( it == s4.end() );
254 BOOST_CHECK_EQUAL(
p.
size(), 1 );
255 BOOST_CHECK(
p[0].first ==
"foo" );
256 BOOST_CHECK_EQUAL(
p[0].second.
size(), 0 );
259 it = extract_parameters(s5.begin(),s5.end(),
p);
260 BOOST_CHECK( it == s5.end() );
261 BOOST_CHECK_EQUAL(
p.
size(), 2 );
262 BOOST_CHECK(
p[0].first ==
"foo" );
263 BOOST_CHECK_EQUAL(
p[0].second.
size(), 0 );
264 BOOST_CHECK(
p[1].first ==
"bar" );
265 BOOST_CHECK_EQUAL(
p[1].second.
size(), 0 );
268 it = extract_parameters(s6.begin(),s6.end(),
p);
269 BOOST_CHECK( it == s6.end() );
270 BOOST_CHECK_EQUAL(
p.
size(), 1 );
271 BOOST_CHECK(
p[0].first ==
"foo" );
273 BOOST_CHECK_EQUAL(
a.size(), 1 );
274 BOOST_CHECK(
a.find(
"bar") !=
a.end() );
275 BOOST_CHECK_EQUAL(
a.find(
"bar")->second,
"" );
278 it = extract_parameters(s7.begin(),s7.end(),
p);
279 BOOST_CHECK( it == s7.end() );
280 BOOST_CHECK_EQUAL(
p.
size(), 2 );
281 BOOST_CHECK(
p[0].first ==
"foo" );
283 BOOST_CHECK_EQUAL(
a.size(), 1 );
284 BOOST_CHECK(
a.find(
"baz") !=
a.end() );
285 BOOST_CHECK_EQUAL(
a.find(
"baz")->second,
"" );
286 BOOST_CHECK(
p[1].first ==
"bar" );
288 BOOST_CHECK_EQUAL(
a.size(), 0 );
291 it = extract_parameters(s8.begin(),s8.end(),
p);
292 BOOST_CHECK( it == s8.end() );
293 BOOST_CHECK_EQUAL(
p.
size(), 1 );
294 BOOST_CHECK(
p[0].first ==
"foo" );
296 BOOST_CHECK_EQUAL(
a.size(), 2 );
297 BOOST_CHECK(
a.find(
"bar") !=
a.end() );
298 BOOST_CHECK_EQUAL(
a.find(
"bar")->second,
"" );
299 BOOST_CHECK(
a.find(
"baz") !=
a.end() );
300 BOOST_CHECK_EQUAL(
a.find(
"baz")->second,
"" );
303 it = extract_parameters(s9.begin(),s9.end(),
p);
304 BOOST_CHECK( it == s9.end() );
305 BOOST_CHECK_EQUAL(
p.
size(), 1 );
306 BOOST_CHECK(
p[0].first ==
"foo" );
308 BOOST_CHECK_EQUAL(
a.size(), 1 );
309 BOOST_CHECK(
a.find(
"bar") !=
a.end() );
310 BOOST_CHECK_EQUAL(
a.find(
"bar")->second,
"baz" );
313 it = extract_parameters(s10.begin(),s10.end(),
p);
314 BOOST_CHECK( it == s10.end() );
315 BOOST_CHECK_EQUAL(
p.
size(), 1 );
316 BOOST_CHECK(
p[0].first ==
"foo" );
318 BOOST_CHECK_EQUAL(
a.size(), 2 );
319 BOOST_CHECK(
a.find(
"bar") !=
a.end() );
320 BOOST_CHECK_EQUAL(
a.find(
"bar")->second,
"baz" );
321 BOOST_CHECK(
a.find(
"boo") !=
a.end() );
322 BOOST_CHECK_EQUAL(
a.find(
"boo")->second,
"" );
325 it = extract_parameters(s11.begin(),s11.end(),
p);
326 BOOST_CHECK( it == s11.end() );
327 BOOST_CHECK_EQUAL(
p.
size(), 2 );
328 BOOST_CHECK(
p[0].first ==
"foo" );
330 BOOST_CHECK_EQUAL(
a.size(), 2 );
331 BOOST_CHECK(
a.find(
"bar") !=
a.end() );
332 BOOST_CHECK_EQUAL(
a.find(
"bar")->second,
"baz" );
333 BOOST_CHECK(
a.find(
"boo") !=
a.end() );
334 BOOST_CHECK_EQUAL(
a.find(
"boo")->second,
"" );
336 BOOST_CHECK_EQUAL(
a.size(), 0 );
339 it = extract_parameters(s12.begin(),s12.end(),
p);
340 BOOST_CHECK( it == s12.end() );
341 BOOST_CHECK_EQUAL(
p.
size(), 1 );
342 BOOST_CHECK(
p[0].first ==
"foo" );
344 BOOST_CHECK_EQUAL(
a.size(), 1 );
345 BOOST_CHECK(
a.find(
"bar") !=
a.end() );
346 BOOST_CHECK_EQUAL(
a.find(
"bar")->second,
"a b c" );
349 it = extract_parameters(s13.begin(),s13.end(),
p);
350 BOOST_CHECK( it == s13.end() );
351 BOOST_CHECK_EQUAL(
p.
size(), 1 );
352 BOOST_CHECK(
p[0].first ==
"foo" );
354 BOOST_CHECK_EQUAL(
a.size(), 1 );
355 BOOST_CHECK(
a.find(
"bar") !=
a.end() );
356 BOOST_CHECK_EQUAL(
a.find(
"bar")->second,
"a \"b\" c" );
488 std::string raw =
"GET / HTTP/1.1\r\nHost: www.example.com\r\nContent-Length: 5\r\n\r\nabcdef";
490 bool exception =
false;
494 pos =
r.consume(raw.c_str(),raw.size());
495 }
catch (std::exception &e) {
497 std::cout << e.what() << std::endl;
500 BOOST_CHECK( exception ==
false );
501 BOOST_CHECK_EQUAL( pos, 65 );
502 BOOST_CHECK(
r.ready() ==
true );
503 BOOST_CHECK_EQUAL(
r.get_version(),
"HTTP/1.1" );
504 BOOST_CHECK_EQUAL(
r.get_method(),
"GET" );
505 BOOST_CHECK_EQUAL(
r.get_uri(),
"/" );
506 BOOST_CHECK_EQUAL(
r.get_header(
"Host"),
"www.example.com" );
507 BOOST_CHECK_EQUAL(
r.get_header(
"Content-Length"),
"5" );
508 BOOST_CHECK_EQUAL(
r.get_body(),
"abcde" );
514 std::string raw =
"GET / HTTP/1.1\r\nHost: www.example.com\r\nContent-Length: 6\r\n\r\nabc";
515 std::string raw2 =
"def";
517 bool exception =
false;
521 pos +=
r.consume(raw.c_str(),raw.size());
522 pos +=
r.consume(raw2.c_str(),raw2.size());
523 }
catch (std::exception &e) {
525 std::cout << e.what() << std::endl;
528 BOOST_CHECK( exception ==
false );
529 BOOST_CHECK_EQUAL( pos, 66 );
530 BOOST_CHECK(
r.ready() ==
true );
531 BOOST_CHECK_EQUAL(
r.get_version(),
"HTTP/1.1" );
532 BOOST_CHECK_EQUAL(
r.get_method(),
"GET" );
533 BOOST_CHECK_EQUAL(
r.get_uri(),
"/" );
534 BOOST_CHECK_EQUAL(
r.get_header(
"Host"),
"www.example.com" );
535 BOOST_CHECK_EQUAL(
r.get_header(
"Content-Length"),
"6" );
536 BOOST_CHECK_EQUAL(
r.get_body(),
"abcdef" );
591 std::string raw =
"GET / HTTP/1.1\r\n";
592 std::string raw2 =
"Host: www.example.com\r\n\r\na";
594 bool exception =
false;
598 pos +=
r.consume(raw.c_str(),raw.size());
599 pos +=
r.consume(raw2.c_str(),raw2.size());
600 }
catch (std::exception &e) {
602 std::cout << e.what() << std::endl;
605 BOOST_CHECK( exception ==
false );
606 BOOST_CHECK( pos == 41 );
607 BOOST_CHECK(
r.ready() ==
true );
608 BOOST_CHECK(
r.get_version() ==
"HTTP/1.1" );
609 BOOST_CHECK(
r.get_method() ==
"GET" );
610 BOOST_CHECK(
r.get_uri() ==
"/" );
611 BOOST_CHECK(
r.get_header(
"Host") ==
"www.example.com" );
617 std::string raw =
"GET / HTTP/1.1\r\nHost: www.example.com\r";
618 std::string raw2 =
"\n\r\na";
620 bool exception =
false;
624 pos +=
r.consume(raw.c_str(),raw.size());
625 pos +=
r.consume(raw2.c_str(),raw2.size());
626 }
catch (std::exception &e) {
628 std::cout << e.what() << std::endl;
631 BOOST_CHECK( exception ==
false );
632 BOOST_CHECK( pos == 41 );
633 BOOST_CHECK(
r.ready() ==
true );
634 BOOST_CHECK(
r.get_version() ==
"HTTP/1.1" );
635 BOOST_CHECK(
r.get_method() ==
"GET" );
636 BOOST_CHECK(
r.get_uri() ==
"/" );
637 BOOST_CHECK(
r.get_header(
"Host") ==
"www.example.com" );
928 std::string raw =
"HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk=\r\nSec-WebSocket-Protocol: chat\r\n\r\n";
930 bool exception =
false;
934 pos +=
r.consume(raw.c_str(),raw.size());
935 }
catch (std::exception &e) {
937 std::cout << e.what() << std::endl;
940 BOOST_CHECK( exception ==
false );
941 BOOST_CHECK_EQUAL( pos, 159 );
942 BOOST_CHECK(
r.headers_ready() ==
true );
943 BOOST_CHECK_EQUAL(
r.get_version(),
"HTTP/1.1" );
945 BOOST_CHECK_EQUAL(
r.get_status_msg(),
"Switching Protocols" );
946 BOOST_CHECK_EQUAL(
r.get_header(
"Upgrade"),
"websocket" );
947 BOOST_CHECK_EQUAL(
r.get_header(
"Connection"),
"Upgrade" );
948 BOOST_CHECK_EQUAL(
r.get_header(
"Sec-WebSocket-Accept"),
"HSmrc0sMlYUkAGmm5OPpG2HaGWk=" );
949 BOOST_CHECK_EQUAL(
r.get_header(
"Sec-WebSocket-Protocol"),
"chat" );
955 std::string raw =
"HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk=\r\nSec-WebSocket-Protocol: chat\r\n\r\n";
958 bool exception =
false;
962 pos +=
r.consume(raw.c_str(),raw.size());
963 }
catch (std::exception &e) {
965 std::cout << e.what() << std::endl;
968 BOOST_CHECK( exception ==
false );
969 BOOST_CHECK_EQUAL( pos, 159 );
970 BOOST_CHECK(
r.headers_ready() ==
true );
971 BOOST_CHECK_EQUAL(
r.get_version(),
"HTTP/1.1" );
973 BOOST_CHECK_EQUAL(
r.get_status_msg(),
"Switching Protocols" );
974 BOOST_CHECK_EQUAL(
r.get_header(
"Upgrade"),
"websocket" );
975 BOOST_CHECK_EQUAL(
r.get_header(
"Connection"),
"Upgrade" );
976 BOOST_CHECK_EQUAL(
r.get_header(
"Sec-WebSocket-Accept"),
"HSmrc0sMlYUkAGmm5OPpG2HaGWk=" );
977 BOOST_CHECK_EQUAL(
r.get_header(
"Sec-WebSocket-Protocol"),
"chat" );
983 std::string raw =
"HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk=\r\nSec-WebSocket-Protocol: chat\r\n\r\n";
986 bool exception =
false;
990 pos +=
r.consume(raw.c_str(),raw.size());
991 }
catch (std::exception &e) {
993 std::cout << e.what() << std::endl;
996 BOOST_CHECK( exception ==
false );
997 BOOST_CHECK_EQUAL( pos, 159 );
998 BOOST_CHECK(
r.headers_ready() ==
true );
999 BOOST_CHECK_EQUAL(
r.get_version(),
"HTTP/1.1" );
1001 BOOST_CHECK_EQUAL(
r.get_status_msg(),
"Switching Protocols" );
1002 BOOST_CHECK_EQUAL(
r.get_header(
"Upgrade"),
"websocket" );
1003 BOOST_CHECK_EQUAL(
r.get_header(
"Connection"),
"Upgrade" );
1004 BOOST_CHECK_EQUAL(
r.get_header(
"Sec-WebSocket-Accept"),
"HSmrc0sMlYUkAGmm5OPpG2HaGWk=" );
1005 BOOST_CHECK_EQUAL(
r.get_header(
"Sec-WebSocket-Protocol"),
"chat" );
1011 std::string raw =
"HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept:HSmrc0sMlYUkAGmm5OPpG2HaGWk=\r\nSec-WebSocket-Protocol: chat\r\n\r\n";
1013 bool exception =
false;
1017 pos +=
r.consume(raw.c_str(),raw.size());
1018 }
catch (std::exception &e) {
1020 std::cout << e.what() << std::endl;
1023 BOOST_CHECK( exception ==
false );
1024 BOOST_CHECK_EQUAL( pos, 158 );
1025 BOOST_CHECK(
r.headers_ready() );
1026 BOOST_CHECK_EQUAL(
r.get_version(),
"HTTP/1.1" );
1028 BOOST_CHECK_EQUAL(
r.get_status_msg(),
"Switching Protocols" );
1029 BOOST_CHECK_EQUAL(
r.get_header(
"Upgrade"),
"websocket" );
1030 BOOST_CHECK_EQUAL(
r.get_header(
"Connection"),
"Upgrade" );
1031 BOOST_CHECK_EQUAL(
r.get_header(
"Sec-WebSocket-Accept"),
"HSmrc0sMlYUkAGmm5OPpG2HaGWk=" );
1032 BOOST_CHECK_EQUAL(
r.get_header(
"Sec-WebSocket-Protocol"),
"chat" );
1038 std::string raw =
"HTTP/1.1 200 OK\r\nDate: Thu, 10 May 2012 11:59:25 GMT\r\nServer: Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8r DAV/2 PHP/5.3.8 with Suhosin-Patch\r\nLast-Modified: Tue, 30 Mar 2010 17:41:28 GMT\r\nETag: \"16799d-55-4830823a78200\"\r\nAccept-Ranges: bytes\r\nContent-Length: 85\r\nVary: Accept-Encoding\r\nContent-Type: text/html\r\n\r\n<!doctype html>\n<html>\n<head>\n<title>Thor</title>\n</head>\n<body> \n<p>Thor</p>\n</body>";
1040 bool exception =
false;
1044 pos +=
r.consume(raw.c_str(),raw.size());
1045 }
catch (std::exception &e) {
1047 std::cout << e.what() << std::endl;
1050 BOOST_CHECK( exception ==
false );
1051 BOOST_CHECK_EQUAL( pos, 405 );
1052 BOOST_CHECK(
r.headers_ready() ==
true );
1053 BOOST_CHECK(
r.ready() ==
true );
1054 BOOST_CHECK_EQUAL(
r.get_version(),
"HTTP/1.1" );
1056 BOOST_CHECK_EQUAL(
r.get_status_msg(),
"OK" );
1057 BOOST_CHECK_EQUAL(
r.get_header(
"Date"),
"Thu, 10 May 2012 11:59:25 GMT" );
1058 BOOST_CHECK_EQUAL(
r.get_header(
"Server"),
"Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8r DAV/2 PHP/5.3.8 with Suhosin-Patch" );
1059 BOOST_CHECK_EQUAL(
r.get_header(
"Last-Modified"),
"Tue, 30 Mar 2010 17:41:28 GMT" );
1060 BOOST_CHECK_EQUAL(
r.get_header(
"ETag"),
"\"16799d-55-4830823a78200\"" );
1061 BOOST_CHECK_EQUAL(
r.get_header(
"Accept-Ranges"),
"bytes" );
1062 BOOST_CHECK_EQUAL(
r.get_header(
"Content-Length"),
"85" );
1063 BOOST_CHECK_EQUAL(
r.get_header(
"Vary"),
"Accept-Encoding" );
1064 BOOST_CHECK_EQUAL(
r.get_header(
"Content-Type"),
"text/html" );
1065 BOOST_CHECK_EQUAL(
r.get_body(),
"<!doctype html>\n<html>\n<head>\n<title>Thor</title>\n</head>\n<body> \n<p>Thor</p>\n</body>" );