Skip to content

net/http: Set-Cookie headers missing when response has multiple #27317

Closed
@nbosscher

Description

@nbosscher

Please answer these questions before submitting your issue. Thanks!

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

go version go1.11 darwin/amd64

Does this issue reproduce with the latest release?

yes

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/natebosscher/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/natebosscher/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.11/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.11/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/82/fks2j_gx5nbgx8mrnpnsn1kr0000gn/T/go-build057971400=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

When I'm requesting an http2 endpoint that sets multiple cookies, not all the cookies are persisting in the cookiejar.

I don't have time to write a full mock up, but here's what I got. This test will fail

func TestCookies(t *testing.T) {

	jar, err := cookiejar.New(&cookiejar.Options{})
	if err != nil {
		t.Fatal(err)
	}

	httpClient := &http.Client{
		Jar: jar,
	}

	form := url.Values{}
	form.Add("UserName", "my-user")
	form.Add("password", "my-password")

	res, err := httpClient.PostForm("https://my-site.com/Account/Login", form)
	if err != nil {
		t.Fatal(err)
	}

	u, err := url.Parse("https://my-site.com/Something")
	if err != nil {
		t.Fatal(err)
	}

	cookies := jar.Cookies(u)
	if len(cookies) != 4 {

		data, _ := httputil.DumpResponse(res, false)
		t.Error(string(data))

		t.Fatal("unexpected number of cookies", len(cookies))
	}

}

Test output:

HTTP/2.0 200 OK
        Cache-Control: private
        Content-Type: text/html; charset=utf-8
        Date: Tue, 28 Aug 2018 18:10:42 GMT
        Server: Microsoft-IIS/10.0
        Set-Cookie: AWSALB=<some-value>; Expires=Tue, 04 Sep 2018 18:10:42 GMT; Path=/
        Vary: Accept-Encoding
        X-Aspnet-Version: 4.0.30319
        X-Aspnetmvc-Version: 5.0
        X-Powered-By: ASP.NET
unexpected number of cookies 1

My server returns something like this

HTTP/2.0 302 
date: Tue, 28 Aug 2018 12:19:25 GMT
content-type: text/html; charset=utf-8
content-length: 118
set-cookie: AWSALB=<some-value>; Expires=Tue, 04 Sep 2018 12:19:25 GMT; Path=/
cache-control: private
location: /
server: Microsoft-IIS/10.0
x-aspnetmvc-version: 5.0
x-aspnet-version: 4.0.30319
set-cookie: .ASPXAUTH=<some-value>; path=/; HttpOnly
set-cookie: employeeName=<some-name>; path=/
set-cookie: EmployeeID=<some-id>; path=/
x-powered-by: ASP.NET

<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="/">here</a>.</h2>
</body></html>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions