]> Cypherpunks repositories - gostls13.git/commit
net/http: do not force the Content-Length header if nilled
authorLaurent Senta <laurent@singulargarden.com>
Fri, 10 Mar 2023 12:33:59 +0000 (12:33 +0000)
committerGopher Robot <gobot@golang.org>
Mon, 15 May 2023 17:07:02 +0000 (17:07 +0000)
commit949d0f4f99c15541d7cd43f3e9812fb7ac9c73db
tree9a8ee1481faf47e0df35087fe379d1bd21745ff5
parent1b896bff30c7622e6d26a1fd30a73d964a860481
net/http: do not force the Content-Length header if nilled

According to the ResponseWriter documentation:

  To suppress automatic response headers (such as "Date"), set
  their value to nil.

In some cases, this documentation is incorrect: chunkWriter writes
a Content-Length header even if the value was set to nil. Meaning
there is no way to suppress this header.

This patch replaces the empty string comparison with a call to
`header.has` which takes into account nil values as expected.
This is similar to the way we handle the "Date" header.

Change-Id: Ie10d54ab0bb7d41270bc944ff867e035fe2bd0c5
GitHub-Last-Rev: e0616dd46388a724df7c6ea821b3808ed1663cab
GitHub-Pull-Request: golang/go#58578
Reviewed-on: https://go-review.googlesource.com/c/go/+/469095
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Damien Neil <dneil@google.com>
Run-TryBot: Jorropo <jorropo.pgm@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
src/net/http/serve_test.go
src/net/http/server.go