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: Set-Cookie headers missing when response has multiple #27317

Closed
nbosscher opened this issue Aug 28, 2018 · 1 comment

Comments

Projects
None yet
1 participant
@nbosscher
Copy link

commented Aug 28, 2018

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>
@nbosscher

This comment has been minimized.

Copy link
Author

commented Aug 29, 2018

Please ignore, it was an issue in my application code

@nbosscher nbosscher closed this Aug 29, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.