http-parser
http-parser copied to clipboard
http_parser: skip lws/rws in header field
Skip whitespace from the left and the right sides of the header field.
See: https://github.com/nodejs/node/pull/5844
cc @jasnell
@indutny ... this is not working as expected. To test it, I added the following test case to test.c:
diff --git a/test.c b/test.c
index 7b01dc3..dac6997 100644
--- a/test.c
+++ b/test.c
@@ -1153,6 +1153,28 @@ const struct message requests[] =
,.body= ""
}
+#if !HTTP_PARSER_STRICT
+#define WHITESPACE_IN_HEADER 42
+, {.name = "whitespace in header"
+ ,.type= HTTP_REQUEST
+ ,.raw= "GET /foo HTTP/1.1\r\n"
+ "XYZ : example.com\r\n"
+ "\r\n"
+ ,.should_keep_alive= TRUE
+ ,.message_complete_on_eof= FALSE
+ ,.http_major= 1
+ ,.http_minor= 1
+ ,.method= HTTP_GET
+ ,.request_path= "/foo"
+ ,.request_url= "/foo"
+ ,.query_string= ""
+ ,.fragment= ""
+ ,.num_headers= 1
+ ,.headers= { { "XYZ", "example.com" } }
+ ,.body= ""
+ }
+#endif
+
, {.name= NULL } /* sentinel */
};
Running make yields:
bash-3.2$ make
./test_g
http_parser v2.6.2 (0x020602)
sizeof(http_parser) = 32
response scan 1/2 100%
response scan 2/2 100%
responses okay
request scan 1/4 100%
request scan 2/4 100%
request scan 3/4 100%
request scan 4/4 100%
requests okay
./test_fast
http_parser v2.6.2 (0x020602)
sizeof(http_parser) = 32
response scan 1/2 100%
response scan 2/2 100%
responses okay
*** Error: header field in 'whitespace in header' ***
expected 'XYZ'
found 'XYZ : example.com
'
make: *** [test] Abort trap: 6
bash-3.2$
Note the value for found.