elixir-plug / plug

Compose web applications with functions
https://hex.pm/packages/plug
Other
2.88k stars 586 forks source link

Refactor get_req_header and get_resp_header #1088

Closed gabrielgiordan closed 2 years ago

gabrielgiordan commented 2 years ago

Instead of iterating through all values, iterates only until the header is found.

When more than one header with same key is sent, like Accept-Language: en_US, Accept-Language: pt_BR, Accept-Language: en_GB, the req_header comes as {"accept-language", "en_US, pt_BR, en_GB"}. So, returning the first found value is fine.

By the way, personally I preferred to return the value itself, but to be backwards compatible, I'm returning it wrapped on a list.

josevalim commented 2 years ago

Unfortunately both HTTP request and response headers can be duplicated. So even if a browser is not sending multiple, an API or anyone can send duplicate and therefore plugs needs to deal with such. Thank you.