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" );
512 websocketpp::http::parser::header_list::const_iterator it = r.
get_headers().begin();
514 BOOST_CHECK_EQUAL( it->first,
"Content-Length");
515 BOOST_CHECK_EQUAL( it->second,
"5");
519 BOOST_CHECK_EQUAL( it->first,
"Host");
520 BOOST_CHECK_EQUAL( it->second,
"www.example.com");
526 std::string raw =
"GET / HTTP/1.1\r\nHost: www.example.com\r\nContent-Length: 6\r\n\r\nabc";
527 std::string raw2 =
"def";
529 bool exception =
false;
533 pos += r.
consume(raw.c_str(),raw.size());
534 pos += r.
consume(raw2.c_str(),raw2.size());
535 }
catch (std::exception &e) {
537 std::cout << e.what() << std::endl;
540 BOOST_CHECK( exception ==
false );
541 BOOST_CHECK_EQUAL( pos, 66 );
542 BOOST_CHECK( r.
ready() == true );
545 BOOST_CHECK_EQUAL( r.
get_uri(),
"/" );
546 BOOST_CHECK_EQUAL( r.
get_header(
"Host"),
"www.example.com" );
547 BOOST_CHECK_EQUAL( r.
get_header(
"Content-Length"),
"6" );
548 BOOST_CHECK_EQUAL( r.
get_body(),
"abcdef" );
556 std::string raw =
"GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\na";
558 bool exception =
false;
562 pos = r.
consume(raw.c_str(),raw.size());
567 BOOST_CHECK( exception ==
false );
568 BOOST_CHECK( pos == 41 );
569 BOOST_CHECK( r.
ready() == true );
572 BOOST_CHECK( r.
get_uri() ==
"/" );
573 BOOST_CHECK( r.
get_header(
"Host") ==
"www.example.com" );
579 std::string raw =
"GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n";
582 bool exception =
false;
586 pos = r.
consume(raw.c_str(),raw.size());
591 BOOST_CHECK( exception ==
false );
592 BOOST_CHECK( pos == 41 );
593 BOOST_CHECK( r.
ready() == true );
596 BOOST_CHECK( r.
get_uri() ==
"/" );
597 BOOST_CHECK( r.
get_header(
"Host") ==
"www.example.com" );
603 std::string raw =
"GET / HTTP/1.1\r\n";
604 std::string raw2 =
"Host: www.example.com\r\n\r\na";
606 bool exception =
false;
610 pos += r.
consume(raw.c_str(),raw.size());
611 pos += r.
consume(raw2.c_str(),raw2.size());
612 }
catch (std::exception &e) {
614 std::cout << e.what() << std::endl;
617 BOOST_CHECK( exception ==
false );
618 BOOST_CHECK( pos == 41 );
619 BOOST_CHECK( r.
ready() == true );
622 BOOST_CHECK( r.
get_uri() ==
"/" );
623 BOOST_CHECK( r.
get_header(
"Host") ==
"www.example.com" );
629 std::string raw =
"GET / HTTP/1.1\r\nHost: www.example.com\r";
630 std::string raw2 =
"\n\r\na";
632 bool exception =
false;
636 pos += r.
consume(raw.c_str(),raw.size());
637 pos += r.
consume(raw2.c_str(),raw2.size());
638 }
catch (std::exception &e) {
640 std::cout << e.what() << std::endl;
643 BOOST_CHECK( exception ==
false );
644 BOOST_CHECK( pos == 41 );
645 BOOST_CHECK( r.
ready() == true );
648 BOOST_CHECK( r.
get_uri() ==
"/" );
649 BOOST_CHECK( r.
get_header(
"Host") ==
"www.example.com" );
658 bool exception =
false;
662 pos += r.
consume(raw.c_str(),raw.size());
669 BOOST_CHECK( exception ==
true );
676 std::string raw2(2,
'*');
678 bool exception =
false;
682 pos += r.
consume(raw.c_str(),raw.size());
683 pos += r.
consume(raw2.c_str(),raw2.size());
690 BOOST_CHECK( exception ==
true );
698 std::string raw =
"GET / HTTP/1.1\r\nHost: www.example.com\r\nContent-Length: 6\r\n\r\nabcdef";
700 bool exception =
false;
704 pos += r.
consume(raw.c_str(),raw.size());
711 BOOST_CHECK( exception ==
true );
717 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";
719 bool exception =
false;
723 pos += r.
consume(raw.c_str(),raw.size());
728 BOOST_CHECK( exception ==
false );
729 BOOST_CHECK( pos == 482 );
730 BOOST_CHECK( r.
ready() == true );
733 BOOST_CHECK( r.
get_uri() ==
"/" );
734 BOOST_CHECK( r.
get_header(
"Host") ==
"localhost:5000" );
735 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" );
736 BOOST_CHECK( r.
get_header(
"Accept") ==
"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" );
737 BOOST_CHECK( r.
get_header(
"Accept-Language") ==
"en-us,en;q=0.5" );
738 BOOST_CHECK( r.
get_header(
"Accept-Encoding") ==
"gzip, deflate" );
739 BOOST_CHECK( r.
get_header(
"Connection") ==
"keep-alive, Upgrade" );
740 BOOST_CHECK( r.
get_header(
"Sec-WebSocket-Version") ==
"8" );
741 BOOST_CHECK( r.
get_header(
"Sec-WebSocket-Origin") ==
"http://zaphoyd.com" );
742 BOOST_CHECK( r.
get_header(
"Sec-WebSocket-Key") ==
"pFik//FxwFk0riN4ZiPFjQ==" );
743 BOOST_CHECK( r.
get_header(
"Pragma") ==
"no-cache" );
744 BOOST_CHECK( r.
get_header(
"Cache-Control") ==
"no-cache" );
745 BOOST_CHECK( r.
get_header(
"Upgrade") ==
"websocket" );
751 std::string raw =
"GE]T / HTTP/1.1\r\nHost: www.example.com\r\n\r\n";
753 bool exception =
false;
756 r.
consume(raw.c_str(),raw.size());
761 BOOST_CHECK( exception ==
true );
767 std::string raw =
"GET / HTTP/1.1\r\nHo]st: www.example.com\r\n\r\n";
769 bool exception =
false;
772 r.
consume(raw.c_str(),raw.size());
777 BOOST_CHECK( exception ==
true );
783 std::string raw =
"GET / HTTP/1.0\r\nHost: www.example.com\r\n\r\n";
785 bool exception =
false;
789 pos = r.
consume(raw.c_str(),raw.size());
794 BOOST_CHECK( exception ==
false );
795 BOOST_CHECK_EQUAL( pos, 41 );
796 BOOST_CHECK( r.
ready() == true );
799 BOOST_CHECK_EQUAL( r.
get_uri(),
"/" );
800 BOOST_CHECK_EQUAL( r.
get_header(
"Host"),
"www.example.com" );
806 std::string raw =
"GET / HTTP/1.12\r\nHost: www.example.com\r\n\r\n";
808 bool exception =
false;
812 pos = r.
consume(raw.c_str(),raw.size());
817 BOOST_CHECK( exception ==
false );
818 BOOST_CHECK_EQUAL( pos, 42 );
819 BOOST_CHECK( r.
ready() == true );
822 BOOST_CHECK_EQUAL( r.
get_uri(),
"/" );
823 BOOST_CHECK_EQUAL( r.
get_header(
"Host"),
"www.example.com" );
829 std::string raw =
"GET / HTTP/12.12\r\nHost: www.example.com\r\n\r\n";
831 bool exception =
false;
835 pos = r.
consume(raw.c_str(),raw.size());
840 BOOST_CHECK( exception ==
false );
841 BOOST_CHECK_EQUAL( pos, 43 );
842 BOOST_CHECK( r.
ready() == true );
843 BOOST_CHECK_EQUAL( r.
get_version(),
"HTTP/12.12" );
845 BOOST_CHECK_EQUAL( r.
get_uri(),
"/" );
846 BOOST_CHECK_EQUAL( r.
get_header(
"Host"),
"www.example.com" );
871 std::string raw =
"GET / HTTP/1.1\r\nHost: www.example.com \r\n\r\n";
873 bool exception =
false;
877 pos = r.
consume(raw.c_str(),raw.size());
882 BOOST_CHECK( exception ==
false );
883 BOOST_CHECK_EQUAL( pos, 43 );
884 BOOST_CHECK( r.
ready() == true );
887 BOOST_CHECK_EQUAL( r.
get_uri(),
"/" );
888 BOOST_CHECK_EQUAL( r.
get_header(
"Host"),
"www.example.com" );
894 std::string raw =
"GET / HTTP/1.1\r\nHost:www.example.com\r\n\r\n";
896 bool exception =
false;
900 pos = r.
consume(raw.c_str(),raw.size());
905 BOOST_CHECK( exception ==
false );
906 BOOST_CHECK_EQUAL( pos, 40 );
907 BOOST_CHECK( r.
ready() == true );
910 BOOST_CHECK_EQUAL( r.
get_uri(),
"/" );
911 BOOST_CHECK_EQUAL( r.
get_header(
"Host"),
"www.example.com" );
917 std::string raw =
"GET / HTTP/1.1\r\nHost: www.example.com\r\nFoo: bar\r\nFoo: bat\r\n\r\n";
919 bool exception =
false;
923 pos = r.
consume(raw.c_str(),raw.size());
928 BOOST_CHECK( exception ==
false );
929 BOOST_CHECK_EQUAL( pos, 61 );
930 BOOST_CHECK( r.
ready() == true );
933 BOOST_CHECK_EQUAL( r.
get_uri(),
"/" );
934 BOOST_CHECK_EQUAL( r.
get_header(
"Foo"),
"bar, bat" );
940 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";
942 bool exception =
false;
946 pos += r.
consume(raw.c_str(),raw.size());
947 }
catch (std::exception &e) {
949 std::cout << e.what() << std::endl;
952 BOOST_CHECK( exception ==
false );
953 BOOST_CHECK_EQUAL( pos, 159 );
958 BOOST_CHECK_EQUAL( r.
get_header(
"Upgrade"),
"websocket" );
959 BOOST_CHECK_EQUAL( r.
get_header(
"Connection"),
"Upgrade" );
960 BOOST_CHECK_EQUAL( r.
get_header(
"Sec-WebSocket-Accept"),
"HSmrc0sMlYUkAGmm5OPpG2HaGWk=" );
961 BOOST_CHECK_EQUAL( r.
get_header(
"Sec-WebSocket-Protocol"),
"chat" );
967 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";
970 bool exception =
false;
974 pos += r.
consume(raw.c_str(),raw.size());
975 }
catch (std::exception &e) {
977 std::cout << e.what() << std::endl;
980 BOOST_CHECK( exception ==
false );
981 BOOST_CHECK_EQUAL( pos, 159 );
986 BOOST_CHECK_EQUAL( r.
get_header(
"Upgrade"),
"websocket" );
987 BOOST_CHECK_EQUAL( r.
get_header(
"Connection"),
"Upgrade" );
988 BOOST_CHECK_EQUAL( r.
get_header(
"Sec-WebSocket-Accept"),
"HSmrc0sMlYUkAGmm5OPpG2HaGWk=" );
989 BOOST_CHECK_EQUAL( r.
get_header(
"Sec-WebSocket-Protocol"),
"chat" );
995 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";
998 bool exception =
false;
1002 pos += r.
consume(raw.c_str(),raw.size());
1003 }
catch (std::exception &e) {
1005 std::cout << e.what() << std::endl;
1008 BOOST_CHECK( exception ==
false );
1009 BOOST_CHECK_EQUAL( pos, 159 );
1014 BOOST_CHECK_EQUAL( r.
get_header(
"Upgrade"),
"websocket" );
1015 BOOST_CHECK_EQUAL( r.
get_header(
"Connection"),
"Upgrade" );
1016 BOOST_CHECK_EQUAL( r.
get_header(
"Sec-WebSocket-Accept"),
"HSmrc0sMlYUkAGmm5OPpG2HaGWk=" );
1017 BOOST_CHECK_EQUAL( r.
get_header(
"Sec-WebSocket-Protocol"),
"chat" );
1023 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";
1025 bool exception =
false;
1029 pos += r.
consume(raw.c_str(),raw.size());
1030 }
catch (std::exception &e) {
1032 std::cout << e.what() << std::endl;
1035 BOOST_CHECK( exception ==
false );
1036 BOOST_CHECK_EQUAL( pos, 158 );
1041 BOOST_CHECK_EQUAL( r.
get_header(
"Upgrade"),
"websocket" );
1042 BOOST_CHECK_EQUAL( r.
get_header(
"Connection"),
"Upgrade" );
1043 BOOST_CHECK_EQUAL( r.
get_header(
"Sec-WebSocket-Accept"),
"HSmrc0sMlYUkAGmm5OPpG2HaGWk=" );
1044 BOOST_CHECK_EQUAL( r.
get_header(
"Sec-WebSocket-Protocol"),
"chat" );
1050 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>";
1052 bool exception =
false;
1056 pos += r.
consume(raw.c_str(),raw.size());
1057 }
catch (std::exception &e) {
1059 std::cout << e.what() << std::endl;
1062 BOOST_CHECK( exception ==
false );
1063 BOOST_CHECK_EQUAL( pos, 405 );
1065 BOOST_CHECK( r.
ready() == true );
1069 BOOST_CHECK_EQUAL( r.
get_header(
"Date"),
"Thu, 10 May 2012 11:59:25 GMT" );
1070 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" );
1071 BOOST_CHECK_EQUAL( r.
get_header(
"Last-Modified"),
"Tue, 30 Mar 2010 17:41:28 GMT" );
1072 BOOST_CHECK_EQUAL( r.
get_header(
"ETag"),
"\"16799d-55-4830823a78200\"" );
1073 BOOST_CHECK_EQUAL( r.
get_header(
"Accept-Ranges"),
"bytes" );
1074 BOOST_CHECK_EQUAL( r.
get_header(
"Content-Length"),
"85" );
1075 BOOST_CHECK_EQUAL( r.
get_header(
"Vary"),
"Accept-Encoding" );
1076 BOOST_CHECK_EQUAL( r.
get_header(
"Content-Type"),
"text/html" );
1077 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>" );
1083 std::stringstream s;
1085 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>";
1087 bool exception =
false;
1092 }
catch (std::exception &e) {
1094 std::cout << e.what() << std::endl;
1097 BOOST_CHECK_EQUAL( exception,
false );
1098 BOOST_CHECK_EQUAL( pos, 405 );
1100 BOOST_CHECK_EQUAL( r.
ready(), true );
1106 std::string raw =
"GET / HTTP/1.1\r\n\r\n";
1112 BOOST_CHECK_EQUAL( r.
raw(), raw );
1118 std::string raw =
"GET / HTTP/1.1\r\nHost: http://example.com\r\n\r\n";
1125 BOOST_CHECK_EQUAL( r.
raw(), raw );
1131 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";
1137 r.
replace_header(
"Content-Type",
"application/x-www-form-urlencoded");
1138 r.
set_body(
"licenseID=string&content=string¶msXML=string");
1140 BOOST_CHECK_EQUAL( r.
raw(), raw );
std::string const & get_header(std::string const &key) const
Get the value of an HTTP header.
BOOST_AUTO_TEST_CASE(is_token_char)
bool ready() const
Returns true if the response is ready.
size_t get_max_body_size() const
Get body size limit.
header_list const & get_headers() const
Return a list of all HTTP headers.
status_code::value m_error_code
void set_body(std::string const &value)
Set body content.
std::vector< std::pair< std::string, attribute_list > > parameter_list
The type of an HTTP parameter list.
bool is_not_token_char(unsigned char c)
Is the character a non-token.
status_code::value get_status_code() const
Return the response status code.
Stores, parses, and manipulates HTTP responses.
std::string const & get_version() const
Get the HTTP version string.
InputIterator extract_parameters(InputIterator begin, InputIterator end, parameter_list ¶meters)
Extract HTTP parameters.
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.
std::string const & get_uri() const
Return the requested URI.
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.
std::string const & get_method() const
Return the request method.
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::string raw() const
Returns the full raw request (including the body)
bool ready() const
Returns whether or not the request is ready for reading.
std::pair< std::string, InputIterator > extract_token(InputIterator begin, InputIterator end)
Read and return the next token in the stream.
bool headers_ready() const
Returns true if the response headers are fully parsed.
const std::string & get_status_msg() const
Return the response status message.
std::string const & get_body() const
Get HTTP body.
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.
void set_max_body_size(size_t value)
Set body size limit.