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

White spaces in header fields will cause parser failed #297

Closed
@chenzhiwei

Description

@chenzhiwei

When the header fields contains white spaces, it will failed.

A sample case, there is a white space before colon in header field.

Content-Length : 5\r\n

Activity

indutny

indutny commented on Apr 5, 2016

@indutny
Member

I believe http-parser will fail only in a strict mode. May I ask you to share more details with us?

chenzhiwei

chenzhiwei commented on Apr 5, 2016

@chenzhiwei
Author

When the http response header is something like this:

HTTP/1.1 200 OK\r\n
Content-Length : 123\r\n
\r\n
body data

Please pay attention to the white spaces after Content-Length and before the colon.

I encountered this error in Mesos project: apache/mesos@b2c92ee#diff-cce67628b066393859924dbdfc3e0fb5L658

The bug URL: https://issues.apache.org/jira/browse/MESOS-5063

indutny

indutny commented on Apr 5, 2016

@indutny
Member

I indeed see the whitespace before the colon, but still not sure what kind of failure you are experiencing. From what I have tried a week ago, it really looked like http-parser supports whitespace before the colon.

May I ask you help me understand it?

chenzhiwei

chenzhiwei commented on Apr 5, 2016

@chenzhiwei
Author

Yes, I thought http-parser 2.6.2 solved this issue, but actually not.

You can insert a white space in this line, then do a make action, it will show you errors.

https://github.com/nodejs/http-parser/blob/v2.6.2/test.c#L1172

chenzhiwei

chenzhiwei commented on Apr 5, 2016

@chenzhiwei
Author

More detailed:

data = "HTTP/1.1 200 OK\r\nContent-Length : 12\r\n\r\nHello World!";
length = 52;
size_t parsed = http_parser_execute(&parser, &settings, data, length);

The parsed and the real length are not same.

chenzhiwei

chenzhiwei commented on Apr 7, 2016

@chenzhiwei
Author

@indutny Could you take a look about this issue? Thanks.

chenzhiwei

chenzhiwei commented on Apr 13, 2016

@chenzhiwei
Author

Set the HTTP_PARSER_STRICT=0 solved my issue, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @indutny@chenzhiwei

        Issue actions

          White spaces in header fields will cause parser failed · Issue #297 · nodejs/http-parser