seanmonstar / httparse

A push parser for the HTTP 1.x protocol in Rust.
https://docs.rs/httparse
Apache License 2.0
573 stars 113 forks source link

Allow spaces in header name #52

Closed xdmiodz closed 5 years ago

xdmiodz commented 5 years ago

It might be inconsistent to have a space in header names, but some legacy systems have such. Is it possible to support them in the httparse?

xdmiodz commented 5 years ago

For me it's ok just strip the spaces from the header name or ignore the header at all

seanmonstar commented 5 years ago

What do other parsers do? Like http_parser, or Netty, or Golang?

xdmiodz commented 5 years ago

Golang allows such headers without any modifications. You can see it here https://golang.org/src/net/http/header.go, fn CanonicalHeaderKey

seanmonstar commented 5 years ago

Hm, no, looking further, it seems headers in Golang with spaces are rejected: https://github.com/golang/go/blob/master/src/net/http/server.go#L992

Spaces have been forbidden in header names since the HTTP/1.0 RFC. I'd rather not permit them.

nox commented 3 years ago

For anyone wondering in the future, that was the golang/go line linked by Sean: https://github.com/golang/go/blob/c5cf6624076a644906aa7ec5c91c4e01ccd375d3/src/net/http/server.go#L992

nox commented 3 years ago

Note that Firefox will skip headers whose name is invalid but will nonetheless parse the rest of the headers and not return an error. https://searchfox.org/mozilla-central/rev/bff70a63cff89284426d82ded6469ed708ef68b7/netwerk/protocol/http/nsHttpHeaderArray.cpp#352