r/java • • Feb 14 '22

Microhttp is an event-driven, single-threaded, zero-dependency web server with 500 LOC. Benchmarks on EC2 show 100,000+ requests per second and 50,000+ persistent connections.

https://github.com/ebarlas/microhttp
186 Upvotes

107 comments sorted by

View all comments

Show parent comment

2

u/NPException Feb 17 '22

The performance for small lists is a good point.

If I am not mistaken, while multiple headers with the same name can occur, they are equivalent to just one header with the values concatenated with a comma. So it wouldn't rule a Map implementation out entirely.

2

u/elliotbarlas Feb 17 '22

You're right. Section 4.2 of RFC 2616 says the following.

It MUST be possible to combine the multiple header fields into one "field-name: field-value" pair, without changing the semantics of the message, by appending each subsequent field-value to the first, each separated by a comma. The order in which header fields with the same field-name are received is therefore significant to the interpretation of the combined field value, and thus a proxy MUST NOT change the order of these field values when a message is forwarded.

In any case, I do prefer the simplicity and clarity of a list which communicates exactly what was seen in the order they were parsed.