Skip to content

net/http: Proto field empty for Requests passed to CheckRedirect after the first #31441

@andymacau853

Description

@andymacau853

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

$ go version
go version go1.11.4 windows/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Administrator\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Project\Go\maas
set GOPROXY=
set GORACE=
set GOROOT=C:\Go
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=
0 -fdebug-prefix-map=C:\Users\Administrator\AppData\Local\Temp\go-build757481154=/tmp/go-
build -gno-record-gcc-switches

What did you do?

  1. I have CheckRedirect functions for check http's redirect.
  2. When first time jump into CheckRedirect for http redirect, the Proto can show HTTP/1.1
  3. When second time jump into CheckRedirect for http redirect or later, the Proto always show empty string!!!!
func Work2() {
	req, _ := http.NewRequest(
		http.MethodGet,
		"http://www.google.com",
		nil,
	)
	req.Header.Set("Accept", "text/html, application/xhtml+xml, */*")
	req.Header.Set("Accept-Language", "zh-TW")
	req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko")

	seq := 0
	res, err := (&http.Client{
		CheckRedirect: func(r *http.Request, v []*http.Request) error {
			request := v[seq].Method + " " + v[seq].URL.RequestURI() + " " + v[seq].Proto
			response := r.Response.Proto + " " + r.Response.Status
			seq++
			log.Println(request)
			log.Println(response)
			return nil
		},
	}).Do(req)
	if err != nil {
		log.Println(err)
	}
	defer res.Body.Close()
	request := res.Request.Method + " " + res.Request.URL.RequestURI() + " " + res.Request.Proto
	response := res.Proto + " " + res.Status
	log.Println(request)
	log.Println(response)
}

What did you expect to see?

Every time get the variable: Proto, always return HTTP/1.1
2019/04/12 22:52:02 GET / HTTP/1.1
2019/04/12 22:52:02 HTTP/1.1 302 Found
2019/04/12 22:52:02 GET /intl/zh-TW/ HTTP/1.1
2019/04/12 22:52:02 HTTP/1.1 302 Found
2019/04/12 22:52:02 GET /?hl=zh-TW HTTP/1.1
2019/04/12 22:52:02 HTTP/1.1 302 Found
2019/04/12 22:52:02 GET /?hl=zh-TW&gws_rd=ssl HTTP/1.1
2019/04/12 22:52:02 HTTP/2.0 200 OK

What did you see instead?

2019/04/12 22:52:02 GET / HTTP/1.1
2019/04/12 22:52:02 HTTP/1.1 302 Found
2019/04/12 22:52:02 GET /intl/zh-TW/
2019/04/12 22:52:02 HTTP/1.1 302 Found
2019/04/12 22:52:02 GET /?hl=zh-TW
2019/04/12 22:52:02 HTTP/1.1 302 Found
2019/04/12 22:52:02 GET /?hl=zh-TW&gws_rd=ssl
2019/04/12 22:52:02 HTTP/2.0 200 OK

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.help wanted

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions