Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/http/httputil: DumpRequest duplicates the 'Connection: close' header #54616

Closed
jimen0 opened this issue Aug 23, 2022 · 2 comments
Closed
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.

Comments

@jimen0
Copy link
Contributor

jimen0 commented Aug 23, 2022

What version of Go are you using (go version)?

$ gotip version
go version devel go1.20-9f0f87c806 Tue Aug 23 06:11:32 2022 +0000 darwin/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ gotip env
GO111MODULE="on"
GOARCH="amd64"
GOBIN="/Users/.../bin"
GOCACHE="/Users/.../Library/Caches/go-build"
GOENV="/Users/.../Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/.../pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/..."
GOPRIVATE="REDACTED"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/.../sdk/gotip"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/.../sdk/gotip/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="devel go1.20-9f0f87c806 Tue Aug 23 06:11:32 2022 +0000"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="0"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/b6/ycbtfvh11373tq5d7mpvmg_h0000gn/T/go-build1281822184=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Send a simple HTTP GET request using curl to a Go's HTTP server and dump it using httputil.DumpRequest. The server code:

package main

import (
	"fmt"
	"io"
	"log"
	"net/http"
	"net/http/httputil"
)

func main() {
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		b, _ := httputil.DumpRequest(r, true)
		fmt.Printf("%s\n", b)

		w.WriteHeader(http.StatusOK)
		io.WriteString(w, "OK")
	})

	if err := http.ListenAndServe("127.0.0.1:10000", nil); err != nil {
		log.Fatalf("failed to listen: %v", err)
	}
}

The curl command:

$ curl -i http://127.0.0.1:10000/ -H 'Connection: close'

What did you expect to see?

Go server printing the same request I see in Wireshark.

What did you see instead?

Go's httputil.DumpRequest duplicating the Connection header.

$ gotip run .
GET / HTTP/1.1
Host: 127.0.0.1:10000
Connection: close
Accept: */*
Connection: close
User-Agent: curl/7.79.1

While this is what Wireshark sees (Follow TCP stream view):

GET / HTTP/1.1
Host: 127.0.0.1:10000
User-Agent: curl/7.79.1
Accept: */*
Connection: close

HTTP/1.1 200 OK
Date: Tue, 23 Aug 2022 08:59:42 GMT
Content-Length: 2
Content-Type: text/plain; charset=utf-8
Connection: close

OK

The issue seems to come from https://cs.opensource.google/go/go/+/refs/tags/go1.19:src/net/http/httputil/dump.go;l=261-263. I'd be happy to contribute a CL and a test fixing this behavior.

@seankhliao seankhliao added the NeedsFix The path to resolution is known, but the work has not been done. label Aug 23, 2022
@seankhliao
Copy link
Member

feel free to send a fix + tests

@gopherbot
Copy link

Change https://go.dev/cl/425155 mentions this issue: net/http/httputil: do not duplicate 'Connection: close' headers

@golang golang locked and limited conversation to collaborators Aug 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

3 participants