28 #define BOOST_TEST_MODULE http_parser 29 #include <boost/test/unit_test.hpp> 57 for (
int i = 0x30; i < 0x3a; i++) {
62 for (
int i = 0x41; i < 0x5b; i++) {
67 for (
int i = 0x61; i < 0x7b; i++) {
74 for (
int i = 0; i < 33; i++) {
98 for (
int i = 127; i < 256; i++) {
108 std::string d1 =
"foo";
109 std::string d2 =
" foo ";
111 std::pair<std::string,std::string::const_iterator> ret;
114 BOOST_CHECK( ret.first ==
"foo" );
115 BOOST_CHECK( ret.second == d1.begin()+3 );
118 BOOST_CHECK( ret.first.empty() );
119 BOOST_CHECK( ret.second == d2.begin()+0 );
122 BOOST_CHECK( ret.first ==
"foo" );
123 BOOST_CHECK( ret.second == d2.begin()+4 );
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;
138 BOOST_CHECK( ret.first ==
"foo" );
139 BOOST_CHECK( ret.second == d1.end() );
142 BOOST_CHECK( ret.first ==
"foo\"bar\"baz" );
143 BOOST_CHECK( ret.second == d2.end() );
146 BOOST_CHECK( ret.first ==
"foo" );
147 BOOST_CHECK( ret.second == d3.begin()+5 );
150 BOOST_CHECK( ret.first.empty() );
151 BOOST_CHECK( ret.second == d4.begin() );
154 BOOST_CHECK( ret.first.empty() );
155 BOOST_CHECK( ret.second == d5.begin() );
159 std::string d1 =
" foo bar";
160 d1.append(1,
char(9));
161 d1.append(
"baz\r\n d\r\n \r\n e\r\nf");
163 std::string::const_iterator ret;
166 BOOST_CHECK( ret == d1.begin()+1 );
169 BOOST_CHECK( ret == d1.begin()+1 );
172 BOOST_CHECK( ret == d1.begin()+9 );
175 BOOST_CHECK( ret == d1.begin()+13 );
178 BOOST_CHECK( ret == d1.begin()+19 );
181 BOOST_CHECK( ret == d1.begin()+28 );
184 BOOST_CHECK( ret == d1.begin()+29 );
191 std::string::const_iterator it;
194 BOOST_CHECK( it == s.begin() );
195 BOOST_CHECK_EQUAL( a.size(), 0 );
199 std::string s =
"foo";
202 std::string::const_iterator it;
205 BOOST_CHECK( it == s.end() );
206 BOOST_CHECK_EQUAL( a.size(), 1 );
207 BOOST_CHECK( a.find(
"foo") != a.end() );
208 BOOST_CHECK_EQUAL( a.find(
"foo")->second,
"" );
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;
235 BOOST_CHECK( it == s1.begin() );
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 );
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 );
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 );
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 );
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,
"" );
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 );
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,
"" );
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" );
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,
"" );
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 );
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" );
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" );
360 std::string test1 =
"foo";
361 std::string test2 =
" foo ";
362 std::string test3 =
"foo ";
363 std::string test4 =
" foo";
364 std::string test5 =
" foo ";
365 std::string test6 =
" \r\n foo ";
366 std::string test7 =
" \t foo ";
367 std::string test8 =
" \t ";
368 std::string test9 =
" \n\r";
386 BOOST_CHECK_EQUAL( r.
get_header(
"foo"),
"bar" );
387 BOOST_CHECK_EQUAL( r.
get_header(
"FOO"),
"bar" );
388 BOOST_CHECK_EQUAL( r.
get_header(
"Foo"),
"bar" );
396 BOOST_CHECK_EQUAL( r.
get_header(
"foo"),
"bar" );
397 BOOST_CHECK_EQUAL( r.
get_header(
"Foo"),
"bar" );
401 BOOST_CHECK_EQUAL( r.
get_header(
"foo"),
"baz" );
402 BOOST_CHECK_EQUAL( r.
get_header(
"Foo"),
"baz" );
415 bool exception =
false;
418 r.
consume(raw.c_str(),raw.size());
423 BOOST_CHECK( exception ==
false );
424 BOOST_CHECK( r.
ready() == false );
430 std::string raw =
"\r\n\r\n";
432 bool exception =
false;
435 r.
consume(raw.c_str(),raw.size());
440 BOOST_CHECK( exception ==
true );
441 BOOST_CHECK( r.
ready() == false );
447 std::string raw =
"GET / HTTP/1.1\r\n\r\n";
449 bool exception =
false;
452 r.
consume(raw.c_str(),raw.size());
457 BOOST_CHECK( exception ==
true );
458 BOOST_CHECK( r.
ready() == false );
464 std::string raw =
"GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n";
466 bool exception =
false;
470 pos = r.
consume(raw.c_str(),raw.size());
471 }
catch (std::exception &e) {
473 std::cout << e.what() << std::endl;
476 BOOST_CHECK( exception ==
false );
477 BOOST_CHECK( pos == 41 );
478 BOOST_CHECK( r.
ready() == true );
481 BOOST_CHECK( r.
get_uri() ==
"/" );
482 BOOST_CHECK( r.
get_header(
"Host") ==
"www.example.com" );
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 );
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 );
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" );
544 std::string raw =
"GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\na";
546 bool exception =
false;
550 pos = r.
consume(raw.c_str(),raw.size());
555 BOOST_CHECK( exception ==
false );
556 BOOST_CHECK( pos == 41 );
557 BOOST_CHECK( r.
ready() == true );
560 BOOST_CHECK( r.
get_uri() ==
"/" );
561 BOOST_CHECK( r.
get_header(
"Host") ==
"www.example.com" );
567 std::string raw =
"GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n";
570 bool exception =
false;
574 pos = r.
consume(raw.c_str(),raw.size());
579 BOOST_CHECK( exception ==
false );
580 BOOST_CHECK( pos == 41 );
581 BOOST_CHECK( r.
ready() == true );
584 BOOST_CHECK( r.
get_uri() ==
"/" );
585 BOOST_CHECK( r.
get_header(
"Host") ==
"www.example.com" );
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 );
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 );
636 BOOST_CHECK( r.
get_uri() ==
"/" );
637 BOOST_CHECK( r.
get_header(
"Host") ==
"www.example.com" );
646 bool exception =
false;
650 pos += r.
consume(raw.c_str(),raw.size());
657 BOOST_CHECK( exception ==
true );
664 std::string raw2(2,
'*');
666 bool exception =
false;
670 pos += r.
consume(raw.c_str(),raw.size());
671 pos += r.
consume(raw2.c_str(),raw2.size());
678 BOOST_CHECK( exception ==
true );
686 std::string raw =
"GET / HTTP/1.1\r\nHost: www.example.com\r\nContent-Length: 6\r\n\r\nabcdef";
688 bool exception =
false;
692 pos += r.
consume(raw.c_str(),raw.size());
699 BOOST_CHECK( exception ==
true );
705 std::string raw =
"GET / HTTP/1.1\r\nHost: localhost:5000\r\nUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:10.0) Gecko/20100101 Firefox/10.0\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nAccept-Language: en-us,en;q=0.5\r\nAccept-Encoding: gzip, deflate\r\nConnection: keep-alive, Upgrade\r\nSec-WebSocket-Version: 8\r\nSec-WebSocket-Origin: http://zaphoyd.com\r\nSec-WebSocket-Key: pFik//FxwFk0riN4ZiPFjQ==\r\nPragma: no-cache\r\nCache-Control: no-cache\r\nUpgrade: websocket\r\n\r\n";
707 bool exception =
false;
711 pos += r.
consume(raw.c_str(),raw.size());
716 BOOST_CHECK( exception ==
false );
717 BOOST_CHECK( pos == 482 );
718 BOOST_CHECK( r.
ready() == true );
721 BOOST_CHECK( r.
get_uri() ==
"/" );
722 BOOST_CHECK( r.
get_header(
"Host") ==
"localhost:5000" );
723 BOOST_CHECK( r.
get_header(
"User-Agent") ==
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:10.0) Gecko/20100101 Firefox/10.0" );
724 BOOST_CHECK( r.
get_header(
"Accept") ==
"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" );
725 BOOST_CHECK( r.
get_header(
"Accept-Language") ==
"en-us,en;q=0.5" );
726 BOOST_CHECK( r.
get_header(
"Accept-Encoding") ==
"gzip, deflate" );
727 BOOST_CHECK( r.
get_header(
"Connection") ==
"keep-alive, Upgrade" );
728 BOOST_CHECK( r.
get_header(
"Sec-WebSocket-Version") ==
"8" );
729 BOOST_CHECK( r.
get_header(
"Sec-WebSocket-Origin") ==
"http://zaphoyd.com" );
730 BOOST_CHECK( r.
get_header(
"Sec-WebSocket-Key") ==
"pFik//FxwFk0riN4ZiPFjQ==" );
731 BOOST_CHECK( r.
get_header(
"Pragma") ==
"no-cache" );
732 BOOST_CHECK( r.
get_header(
"Cache-Control") ==
"no-cache" );
733 BOOST_CHECK( r.
get_header(
"Upgrade") ==
"websocket" );
739 std::string raw =
"GE]T / HTTP/1.1\r\nHost: www.example.com\r\n\r\n";
741 bool exception =
false;
744 r.
consume(raw.c_str(),raw.size());
749 BOOST_CHECK( exception ==
true );
755 std::string raw =
"GET / HTTP/1.1\r\nHo]st: www.example.com\r\n\r\n";
757 bool exception =
false;
760 r.
consume(raw.c_str(),raw.size());
765 BOOST_CHECK( exception ==
true );
771 std::string raw =
"GET / HTTP/1.0\r\nHost: www.example.com\r\n\r\n";
773 bool exception =
false;
777 pos = r.
consume(raw.c_str(),raw.size());
782 BOOST_CHECK( exception ==
false );
783 BOOST_CHECK_EQUAL( pos, 41 );
784 BOOST_CHECK( r.
ready() == true );
787 BOOST_CHECK_EQUAL( r.
get_uri(),
"/" );
788 BOOST_CHECK_EQUAL( r.
get_header(
"Host"),
"www.example.com" );
794 std::string raw =
"GET / HTTP/1.12\r\nHost: www.example.com\r\n\r\n";
796 bool exception =
false;
800 pos = r.
consume(raw.c_str(),raw.size());
805 BOOST_CHECK( exception ==
false );
806 BOOST_CHECK_EQUAL( pos, 42 );
807 BOOST_CHECK( r.
ready() == true );
810 BOOST_CHECK_EQUAL( r.
get_uri(),
"/" );
811 BOOST_CHECK_EQUAL( r.
get_header(
"Host"),
"www.example.com" );
817 std::string raw =
"GET / HTTP/12.12\r\nHost: www.example.com\r\n\r\n";
819 bool exception =
false;
823 pos = r.
consume(raw.c_str(),raw.size());
828 BOOST_CHECK( exception ==
false );
829 BOOST_CHECK_EQUAL( pos, 43 );
830 BOOST_CHECK( r.
ready() == true );
831 BOOST_CHECK_EQUAL( r.
get_version(),
"HTTP/12.12" );
833 BOOST_CHECK_EQUAL( r.
get_uri(),
"/" );
834 BOOST_CHECK_EQUAL( r.
get_header(
"Host"),
"www.example.com" );
859 std::string raw =
"GET / HTTP/1.1\r\nHost: www.example.com \r\n\r\n";
861 bool exception =
false;
865 pos = r.
consume(raw.c_str(),raw.size());
870 BOOST_CHECK( exception ==
false );
871 BOOST_CHECK_EQUAL( pos, 43 );
872 BOOST_CHECK( r.
ready() == true );
875 BOOST_CHECK_EQUAL( r.
get_uri(),
"/" );
876 BOOST_CHECK_EQUAL( r.
get_header(
"Host"),
"www.example.com" );
882 std::string raw =
"GET / HTTP/1.1\r\nHost:www.example.com\r\n\r\n";
884 bool exception =
false;
888 pos = r.
consume(raw.c_str(),raw.size());
893 BOOST_CHECK( exception ==
false );
894 BOOST_CHECK_EQUAL( pos, 40 );
895 BOOST_CHECK( r.
ready() == true );
898 BOOST_CHECK_EQUAL( r.
get_uri(),
"/" );
899 BOOST_CHECK_EQUAL( r.
get_header(
"Host"),
"www.example.com" );
905 std::string raw =
"GET / HTTP/1.1\r\nHost: www.example.com\r\nFoo: bar\r\nFoo: bat\r\n\r\n";
907 bool exception =
false;
911 pos = r.
consume(raw.c_str(),raw.size());
916 BOOST_CHECK( exception ==
false );
917 BOOST_CHECK_EQUAL( pos, 61 );
918 BOOST_CHECK( r.
ready() == true );
921 BOOST_CHECK_EQUAL( r.
get_uri(),
"/" );
922 BOOST_CHECK_EQUAL( r.
get_header(
"Foo"),
"bar, bat" );
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 );
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 );
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 );
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 );
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 );
1053 BOOST_CHECK( r.
ready() == true );
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>" );
1071 std::stringstream s;
1073 s <<
"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>";
1075 bool exception =
false;
1080 }
catch (std::exception &e) {
1082 std::cout << e.what() << std::endl;
1085 BOOST_CHECK_EQUAL( exception,
false );
1086 BOOST_CHECK_EQUAL( pos, 405 );
1088 BOOST_CHECK_EQUAL( r.
ready(), true );
1094 std::string raw =
"GET / HTTP/1.1\r\n\r\n";
1100 BOOST_CHECK_EQUAL( r.
raw(), raw );
1106 std::string raw =
"GET / HTTP/1.1\r\nHost: http://example.com\r\n\r\n";
1113 BOOST_CHECK_EQUAL( r.
raw(), raw );
1119 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";
1125 r.
replace_header(
"Content-Type",
"application/x-www-form-urlencoded");
1126 r.
set_body(
"licenseID=string&content=string¶msXML=string");
1128 BOOST_CHECK_EQUAL( r.
raw(), raw );
size_t get_max_body_size() const
Get body size limit.
BOOST_AUTO_TEST_CASE(is_token_char)
std::string raw() const
Returns the full raw request (including the body)
status_code::value m_error_code
std::string const & get_body() const
Get HTTP body.
void set_body(std::string const &value)
Set body content.
status_code::value get_status_code() const
Return the response status code.
std::vector< std::pair< std::string, attribute_list > > parameter_list
The type of an HTTP parameter list.
std::string const & get_uri() const
Return the requested URI.
bool is_not_token_char(unsigned char c)
Is the character a non-token.
Stores, parses, and manipulates HTTP responses.
bool ready() const
Returns true if the response is ready.
std::string const & get_header(std::string const &key) const
Get the value of an HTTP header.
std::string const & get_version() const
Get the HTTP version string.
InputIterator extract_parameters(InputIterator begin, InputIterator end, parameter_list ¶meters)
Extract HTTP parameters.
bool headers_ready() const
Returns true if the response headers are fully parsed.
InputIterator extract_attributes(InputIterator begin, InputIterator end, attribute_list &attributes)
Extract HTTP attributes.
std::pair< std::string, InputIterator > extract_quoted_string(InputIterator begin, InputIterator end)
Read and return the next quoted string in the stream.
size_t const max_header_size
Maximum size in bytes before rejecting an HTTP header as too big.
std::map< std::string, std::string > attribute_list
The type of an HTTP attribute list.
std::string strip_lws(std::string const &input)
void replace_header(std::string const &key, std::string const &val)
Set a value for an HTTP header, replacing an existing value.
void set_uri(std::string const &uri)
Set the HTTP uri. Must be a valid HTTP uri.
void set_version(std::string const &version)
Set HTTP parser Version.
Stores, parses, and manipulates HTTP requests.
size_t consume(char const *buf, size_t len)
Process bytes in the input buffer.
void set_method(std::string const &method)
Set the HTTP method. Must be a valid HTTP token.
size_t consume(char const *buf, size_t len)
Process bytes in the input buffer.
InputIterator extract_all_lws(InputIterator begin, InputIterator end)
Read and discard linear whitespace.
std::pair< std::string, InputIterator > extract_token(InputIterator begin, InputIterator end)
Read and return the next token in the stream.
bool ready() const
Returns whether or not the request is ready for reading.
void remove_header(std::string const &key)
Remove a header from the parser.
bool is_token_char(unsigned char c)
Is the character a token.
const std::string & get_status_msg() const
Return the response status message.
std::string const & get_method() const
Return the request method.
void set_max_body_size(size_t value)
Set body size limit.