go-chi / go-chi/chi

Content-Encoding header is not being properly parsed

Open
#959 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Go
Stars
22.9k
Forks
1.4k
Avg merge
5h 17m
Merged PRs (30d)
10

Description

Content encodings can be supplied by multiple `Content-Encoding` headers or by one header with a comma separated list of encodings as seen [here](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding).

The `Header` map embedded in an `http.Request` from the Go standard library states that:

```
Header contains the request header fields either received by the server or to be sent by the client.

If a server received a request with header lines,

Host: example.com
accept-encoding: gzip, deflate
Accept-Language: en-us
fOO: Bar
foo: two
then

Header = map[string][]string{
"Accept-Encoding": {"gzip, deflate"},
"Accept-Language": {"en-us"},
"Foo": {"Bar", "two"},
}
```

As seen by the `Accept-Encoding` header, this means a comma separated list of values will be returned as a `[]string` with a _single_ element.

Currently, `chi` does not make this distinction, and so it is not properly parsing the `Content-Encoding` header.

I will submit a PR fixing this issue shortly.

Contributor guide

Open the contributing guide

Research direction

Start by locating chi's handling of the Content-Encoding header and compare it with Go's http.Header behavior described in the issue. Check how repeated headers and comma-separated values are represented, then add coverage for both forms; done means both encodings are parsed correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.