golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.13k stars 17.68k forks source link

net/http: response.ContentLength is only considering header key "Content-Length" case sensitive #65604

Closed akrieg-ionos closed 9 months ago

akrieg-ionos commented 9 months ago

Go version

go version go1.22.0 linux/amd64

Output of go env in your module/workspace:

go env
GO111MODULE='on'                                                                                                                                                                                                                                 ─╯
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/akrieg/.cache/go-build'
GOENV='/home/akrieg/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/akrieg/go/pkg/mod'
GONOPROXY='github.com/ionos-cloud'
GONOSUMDB='github.com/ionos-cloud'
GOOS='linux'
GOPATH='/home/akrieg/go'
GOPRIVATE='github.com/ionos-cloud'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.0'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/akrieg/projects/paas/paaskit/go-paaskit/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3927774349=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I want to use response.ContentLength attribute.

What did you see happen?

If the response header has e.g. the key content-length response.ContentLength is not set as only "Content-Length" is taken into account.

What did you expect to see?

However afaik header keys are case insensitive. So, if a response contains Content-Length or e.g. content-length as header should make no difference regarding the response.ContentLength attribute.

seankhliao commented 9 months ago

how are you setting content length? https://pkg.go.dev/net/http#Header documents the expected storage case, while the methods accept case insensitive input and convert accordingly.

jeeftor commented 9 months ago

I'll say I noticed header-keys are case intensive as well... - I even wrote some tests to validate it :)

akrieg-ionos commented 9 months ago

I will try to proof my hypothesis with a test. If I fail, I will close this issue.

danp commented 9 months ago

@akrieg-ionos pretty sure any keys in header at that point would have been canonicalized:

https://github.com/golang/go/blob/1400b268529f1bbacde83b3dc022fec0b196846b/src/net/http/h2_bundle.go#L9450

akrieg-ionos commented 9 months ago

@danp @seankhliao @jeeftor indeed i am wrong with my hypothesis, so i close this. Sorry for the noise and thanks for the feedback. :bouquet: