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

Please increase the demo number of headers #70

Closed jrconlin closed 2 years ago

jrconlin commented 4 years ago

tldr: Please change the documentation demo line from

let mut headers = [httparse::EMPTY_HEADER; 16];
let mut req = httparse::Request::new(&mut headers);

to

let mut headers = [httparse::EMPTY_HEADER; 64];
let mut req = httparse::Request::new(&mut headers);

This is a really silly bug that bit us.

Our server uses httparse. Since we weren't quite sure how many headers we needed to pre-allocate, we used the demo code's suggested 16 headers. Unfortunately, with work going on around the new Sec-* headers, we suddenly saw a spike of clients trying to connect with 17 headers. It took us a bit to figure out what was going on and why these connections were mysteriously failing.

Boosting the count might help others not suddenly hit this problem.

miketaylr commented 4 years ago

@jrconlin I see 64 here, https://docs.rs/httparse/1.3.4/httparse/constant.EMPTY_HEADER.html#example

Is there anywhere else 16 is listed, beyond the README.md, that you're aware of?

jrconlin commented 4 years ago

Not that I'm aware of, no. However, I've not really done a very deep dive to investigate. It's my guess that we used 16 mostly from the README example, but it's been a while and folks forgot where they got the number.

ylxdzsw commented 4 years ago

Got the same problem too. The fact that Chrome sent more headers than cURL and exceeded the pre-allocated number of headers really confused us for a while.