Skip to content
This repository has been archived by the owner on Nov 6, 2022. It is now read-only.

http_parser: skip lws/rws in header field #295

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

indutny
Copy link
Member

@indutny indutny commented Mar 25, 2016

Skip whitespace from the left and the right sides of the header field.

See: nodejs/node#5844

cc @jasnell

Skip whitespace from the left and the right sides of the header field.

See: nodejs/node#5844
@jasnell
Copy link
Member

jasnell commented Apr 11, 2016

@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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants