tomaka / rouille

Web framework in Rust
Apache License 2.0
1.12k stars 106 forks source link

Possible to remove Content-Length header from Responses? #150

Open davechallis opened 6 years ago

davechallis commented 6 years ago

Is there a way to return a Response without a Content-Length header being set?

According to https://tools.ietf.org/html/rfc7230#section-3.3.2 , this header shouldn't be set when returning certain status codes:

"A server MUST NOT send a Content-Length header field in any response
   with a status code of 1xx (Informational) or 204 (No Content)."

I've tried using e.g.:

Response::empty_404().with_status_code(204).without_header("Content-Length")

but still get back:

HTTP/1.1 204 No Content
Server: tiny-http (Rust)
Date: Wed, 11 Oct 2017 16:36:29 GMT
Content-Length: 0
tomaka commented 6 years ago

That's an issue with the tiny-http library. Tiny-http makes sure that you can't send or read too much data from the socket, so it handles this header for rouille.

davechallis commented 6 years ago

Ah, good to know, will take a look in that direction, thanks for the info.