http-parser icon indicating copy to clipboard operation
http-parser copied to clipboard

Custom methods should be supported

Open nazar-pc opened this issue 9 years ago • 7 comments

Initially reported here: https://github.com/nghttp2/nghttp2/issues/602

I see in sources big switch with hardcoded HTTP methods and rejects any custom methods, however, there is nothing in specs that forbids usage of custom methods (see referred issue for examples).

nazar-pc avatar May 25 '16 17:05 nazar-pc

@nazar-pc what about Content-Length and Transfer-Encoding should it be accepted for custom methods, or should we reject methods that pass them? There are some protocol driven semantics that may be very important to implement additional methods.

indutny avatar May 25 '16 17:05 indutny

I do not think there is something fundamentally different here. As per https://tools.ietf.org/html/rfc7231#section-4 I suppose methods not listed in spec are:

  • not safe
  • not idempotent
  • not cacheable (I feel like caching might actually apply if corresponding headers are present though)

Content-Length and Transfer-Encoding do not seem to be specifically tied to methods. So I'd expect custom methods to support them if present. This is what Apache2 and Nginx at least both do in practice and modern browsers also do not have any issues with this. So I'm using custom methods in API when sending AJAX requests sometimes with request body, sometimes without. When body is present there is correct Content-Length, if no body - Content-Length header is not present at all.

nazar-pc avatar May 25 '16 18:05 nazar-pc

What about Upgrade header? Should it still work as usual with custom methods?

Is it safe to assume that there are no "no-body" methods like HEAD?

indutny avatar May 25 '16 18:05 indutny

I'm completely confident about Upgrade. It is allowed for some other methods besides GET? Didn't found anything about this.

I think yes, HEAD is pretty special in this meaning, but, obviously, response might have empty body.

nazar-pc avatar May 25 '16 20:05 nazar-pc

If we pretend that custom methods do not require special treatment of HEAD, then we can follow the rule described in https://tools.ietf.org/html/rfc7230#section-3.3.3, to determine the content length. Of course, this would break if someone standardizes new method which requires special treatment like HEAD or CONNECT.

tatsuhiro-t avatar May 26 '16 13:05 tatsuhiro-t

Here is my PoC #311 I made nghttpx proxy use this new on_method callback, and it works fine.

tatsuhiro-t avatar May 28 '16 10:05 tatsuhiro-t

Any changes on this? Can't wait to see this update applied to have Node parse custom headers.

Fr0sT-Brutal avatar May 05 '17 11:05 Fr0sT-Brutal