The Wayback Machine - https://web.archive.org/web/20200907053650/https://github.com/nodejs/llhttp/pull/54
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle custom methods and protocols #54

Closed
wants to merge 1 commit into from
Closed

Conversation

@alekitto
Copy link

alekitto commented Mar 19, 2020

I've tried to solve #11

This introduced protocol and method additional spans and removed the static methods map.
The removal of the static method map implied a BC break as the http method is now a string and should be retrieved by the embedder registering an on_method callback.

It's pretty dirty in the req_or_res part, where it is trying to guess if the message is a request or a response. IMHO this behavior should be removed completly and the embedder must pass the message type to the parser: I don't really see a real usage application to keep the things mixed up like this.

Hope this could help

@toddwong
Copy link

toddwong commented Aug 16, 2020

Please someone mege this?

@indutny
Copy link
Member

indutny commented Aug 21, 2020

Hey!

Thank you for submitting this and sorry I didn't get back to you earlier.

Adding new HTTP methods is tricky in HTTP 1.1. According to the protocol different methods might imply presence or absence of body in the request/response. It is not possible to apriori know it without hand-coding this semantic into it.

Secondly, and likely more importantly with this patch the burden of parsing the HTTP method is shifted to the user of the library, and the optimization (happening in llparse) is not utilized for method parsing at all. I don't think this is the direction we want to go to with this library.

With this being said, I suggest we close the Pull Request. I wish you would have had a chance to discuss it with us before you created this sizable patch. Sorry to dismiss you work, but I don't think it is in line with the idea of the llhttp.

Thanks again!

@indutny indutny closed this Aug 21, 2020
@alekitto
Copy link
Author

alekitto commented Aug 21, 2020

Hi @indutny,
I've created a patch for my own use, i thought that could be useful to the community, for this reason I've not discussed it before submitting.

Talking about HTTP 1.1, the RFC 7231 Section 4.1 does not limit HTTP method and defines it as

    method = token

Some methods are standardized in the same RFC, but there's no RFC that restricts methods. The only requirement is that the method MUST contain only characters in US-ASCII charset.

The same RFC also explicit (in section 8.1.2) that

   Since message parsing (Section 3.3 of [RFC7230]) needs to be
   independent of method semantics (aside from responses to HEAD),
   definitions of new methods cannot change the parsing algorithm or
   prohibit the presence of a message body on either the request or the
   response message.

and

   To allow existing parsers to process the
   response message, new status codes cannot disallow a payload,
   although they can mandate a zero-length payload body.

According to this section, excluding GET and HEAD, all the other method including the non-standardized ones must not prohibit the body.

Secondly, and likely more importantly with this patch the burden of parsing the HTTP method is shifted to the user of the library, and the optimization (happening in llparse) is not utilized for method parsing at all.

Regarding this: it's true, unfortunately, but without a method map, it's unavoidable. In addition, this allows to parse HTTP-like messages, but with another protocol (RTSP for example). For this case the method map is not usable and is removed in the patch.

I don't think this is the direction we want to go to with this library.

I think that a roadmap, known issues that will not be fixed or at least the limits that this library will not trespass could help to choose this library as base tool or another parsing library.

IMHO the direction was not clear enough, but if this direction is confirmed, I will personally start evaluating another library for my projects or create a fork.

@indutny
Copy link
Member

indutny commented Aug 27, 2020

Thank you for an elaborated write-up. Your reasoning behind the patch is very sound.

I'd like to invite few members of @nodejs/http here for discussion. There was never a specific roadmap or direction anywhere, but in my head prior to this, but I'm open to improving things!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.