about summary refs log tree commit homepage
diff options
context:
space:
mode:
-rw-r--r--ext/http11/http11_parser.c52
-rw-r--r--ext/http11/http11_parser.rl7
2 files changed, 30 insertions, 29 deletions
diff --git a/ext/http11/http11_parser.c b/ext/http11/http11_parser.c
index c2143de..35ebaf8 100644
--- a/ext/http11/http11_parser.c
+++ b/ext/http11/http11_parser.c
@@ -72,12 +72,11 @@ size_t http_parser_execute(http_parser *parser, const char *buffer, size_t len,
   p = buffer+off;
   pe = buffer+len;
 
-  /* assert(*pe == '\0' && "pointer does not end on NUL"); */
+  assert(*pe == '\0' && "pointer does not end on NUL");
   assert(pe - p == len - off && "pointers aren't same distance");
 
-
   
-#line 81 "http11_parser.c"
+#line 80 "http11_parser.c"
         {
         if ( p == pe )
                 goto _test_eof;
@@ -108,7 +107,7 @@ st2:
         if ( ++p == pe )
                 goto _test_eof2;
 case 2:
-#line 112 "http11_parser.c"
+#line 111 "http11_parser.c"
         switch( (*p) ) {
                 case 32: goto tr2;
                 case 36: goto st38;
@@ -134,7 +133,7 @@ st3:
         if ( ++p == pe )
                 goto _test_eof3;
 case 3:
-#line 138 "http11_parser.c"
+#line 137 "http11_parser.c"
         switch( (*p) ) {
                 case 42: goto tr4;
                 case 43: goto tr5;
@@ -158,7 +157,7 @@ st4:
         if ( ++p == pe )
                 goto _test_eof4;
 case 4:
-#line 162 "http11_parser.c"
+#line 161 "http11_parser.c"
         switch( (*p) ) {
                 case 32: goto tr8;
                 case 35: goto tr9;
@@ -229,7 +228,7 @@ st5:
         if ( ++p == pe )
                 goto _test_eof5;
 case 5:
-#line 233 "http11_parser.c"
+#line 232 "http11_parser.c"
         if ( (*p) == 72 )
                 goto tr10;
         goto st0;
@@ -241,7 +240,7 @@ st6:
         if ( ++p == pe )
                 goto _test_eof6;
 case 6:
-#line 245 "http11_parser.c"
+#line 244 "http11_parser.c"
         if ( (*p) == 84 )
                 goto st7;
         goto st0;
@@ -327,7 +326,7 @@ st14:
         if ( ++p == pe )
                 goto _test_eof14;
 case 14:
-#line 331 "http11_parser.c"
+#line 330 "http11_parser.c"
         if ( (*p) == 10 )
                 goto st15;
         goto st0;
@@ -379,7 +378,7 @@ st57:
         if ( ++p == pe )
                 goto _test_eof57;
 case 57:
-#line 383 "http11_parser.c"
+#line 382 "http11_parser.c"
         goto st0;
 tr21:
 #line 37 "http11_parser.rl"
@@ -395,7 +394,7 @@ st17:
         if ( ++p == pe )
                 goto _test_eof17;
 case 17:
-#line 399 "http11_parser.c"
+#line 398 "http11_parser.c"
         switch( (*p) ) {
                 case 33: goto tr23;
                 case 58: goto tr24;
@@ -434,7 +433,7 @@ st18:
         if ( ++p == pe )
                 goto _test_eof18;
 case 18:
-#line 438 "http11_parser.c"
+#line 437 "http11_parser.c"
         switch( (*p) ) {
                 case 13: goto tr26;
                 case 32: goto tr27;
@@ -448,7 +447,7 @@ st19:
         if ( ++p == pe )
                 goto _test_eof19;
 case 19:
-#line 452 "http11_parser.c"
+#line 451 "http11_parser.c"
         if ( (*p) == 13 )
                 goto tr29;
         goto st19;
@@ -501,7 +500,7 @@ st20:
         if ( ++p == pe )
                 goto _test_eof20;
 case 20:
-#line 505 "http11_parser.c"
+#line 504 "http11_parser.c"
         switch( (*p) ) {
                 case 32: goto tr31;
                 case 37: goto tr32;
@@ -523,7 +522,7 @@ st21:
         if ( ++p == pe )
                 goto _test_eof21;
 case 21:
-#line 527 "http11_parser.c"
+#line 526 "http11_parser.c"
         switch( (*p) ) {
                 case 32: goto tr34;
                 case 37: goto st22;
@@ -545,7 +544,7 @@ st22:
         if ( ++p == pe )
                 goto _test_eof22;
 case 22:
-#line 549 "http11_parser.c"
+#line 548 "http11_parser.c"
         if ( (*p) < 65 ) {
                 if ( 48 <= (*p) && (*p) <= 57 )
                         goto st23;
@@ -576,7 +575,7 @@ st24:
         if ( ++p == pe )
                 goto _test_eof24;
 case 24:
-#line 580 "http11_parser.c"
+#line 579 "http11_parser.c"
         switch( (*p) ) {
                 case 43: goto st24;
                 case 58: goto st25;
@@ -601,7 +600,7 @@ st25:
         if ( ++p == pe )
                 goto _test_eof25;
 case 25:
-#line 605 "http11_parser.c"
+#line 604 "http11_parser.c"
         switch( (*p) ) {
                 case 32: goto tr8;
                 case 34: goto st0;
@@ -648,7 +647,7 @@ st28:
         if ( ++p == pe )
                 goto _test_eof28;
 case 28:
-#line 652 "http11_parser.c"
+#line 651 "http11_parser.c"
         switch( (*p) ) {
                 case 32: goto tr42;
                 case 34: goto st0;
@@ -700,7 +699,7 @@ st31:
         if ( ++p == pe )
                 goto _test_eof31;
 case 31:
-#line 704 "http11_parser.c"
+#line 703 "http11_parser.c"
         switch( (*p) ) {
                 case 32: goto tr8;
                 case 34: goto st0;
@@ -751,7 +750,7 @@ st34:
         if ( ++p == pe )
                 goto _test_eof34;
 case 34:
-#line 755 "http11_parser.c"
+#line 754 "http11_parser.c"
         switch( (*p) ) {
                 case 32: goto tr53;
                 case 34: goto st0;
@@ -772,7 +771,7 @@ st35:
         if ( ++p == pe )
                 goto _test_eof35;
 case 35:
-#line 776 "http11_parser.c"
+#line 775 "http11_parser.c"
         switch( (*p) ) {
                 case 32: goto tr57;
                 case 34: goto st0;
@@ -793,7 +792,7 @@ st36:
         if ( ++p == pe )
                 goto _test_eof36;
 case 36:
-#line 797 "http11_parser.c"
+#line 796 "http11_parser.c"
         if ( (*p) < 65 ) {
                 if ( 48 <= (*p) && (*p) <= 57 )
                         goto st37;
@@ -1208,9 +1207,10 @@ case 56:
         _test_eof: {}
         _out: {}
         }
-#line 122 "http11_parser.rl"
+#line 121 "http11_parser.rl"
 
-  parser->cs = cs;
+  if (!http_parser_has_error(parser))
+    parser->cs = cs;
   parser->nread += p - (buffer + off);
 
   assert(p <= pe && "buffer overflow after parsing execute");
@@ -1239,5 +1239,5 @@ int http_parser_has_error(http_parser *parser) {
 }
 
 int http_parser_is_finished(http_parser *parser) {
-  return parser->cs >= http_parser_first_final;
+  return parser->cs == http_parser_first_final;
 }
diff --git a/ext/http11/http11_parser.rl b/ext/http11/http11_parser.rl
index 5e551a3..c3c4b1f 100644
--- a/ext/http11/http11_parser.rl
+++ b/ext/http11/http11_parser.rl
@@ -114,12 +114,13 @@ size_t http_parser_execute(http_parser *parser, const char *buffer, size_t len,
   p = buffer+off;
   pe = buffer+len;
 
-  /* assert(*pe == '\0' && "pointer does not end on NUL"); */
+  assert(*pe == '\0' && "pointer does not end on NUL");
   assert(pe - p == len - off && "pointers aren't same distance");
 
   %% write exec;
 
-  parser->cs = cs;
+  if (!http_parser_has_error(parser))
+    parser->cs = cs;
   parser->nread += p - (buffer + off);
 
   assert(p <= pe && "buffer overflow after parsing execute");
@@ -148,5 +149,5 @@ int http_parser_has_error(http_parser *parser) {
 }
 
 int http_parser_is_finished(http_parser *parser) {
-  return parser->cs >= http_parser_first_final;
+  return parser->cs == http_parser_first_final;
 }