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: DumpRequestOut excluding Cookie header #22745

Closed
caffeinejolt opened this issue Nov 15, 2017 · 2 comments
Closed

net/http/httputil: DumpRequestOut excluding Cookie header #22745

caffeinejolt opened this issue Nov 15, 2017 · 2 comments

Comments

@caffeinejolt
Copy link

Please answer these questions before submitting your issue. Thanks!

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

go version go1.9.2 windows/amd64

Does this issue reproduce with the latest release?

yes

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

set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\Michael\go
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
set CXX=g++
set CGO_ENABLED=1
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

What did you do?

when using net/http/cookiejar - the cookie jar works and sends out cookies that is receives in subsequent requests - however, on those subsequent requests, httputil.DumpRequestOut does not show the Cookie header - it shows all the other headers that were sent - just not Cookie

I verified the exact headers sent on the server to make sure it was indeed sending the Cookie header

this is obviously not a critical issue - but figured I would pass it along

What did you expect to see?

Per the docs on httputil.DumpRequestOut, I expected to see all headers which were sent

What did you see instead?

All headers sent, except the Cookie header

@caffeinejolt
Copy link
Author

caffeinejolt commented Nov 15, 2017

Some reproduce code (since I don't have a real server to bounce requests off of, I added a cookie to the cookie jar):


package main

import (
	"fmt"
	"net/http"
	"net/http/cookiejar"
	"net/http/httputil"
	"net/url"
	"strings"
	"time"
)

func main() {
	transport := &http.Transport{
		MaxIdleConns:    20,
		IdleConnTimeout: 15 * time.Second, // how quickly are connections that we create GCed
	}
	client := &http.Client{
		Timeout:   10 * time.Second,
		Transport: transport,
		CheckRedirect: func(req *http.Request, via []*http.Request) error {
			return http.ErrUseLastResponse
		},
	}
	cj, _ := cookiejar.New(nil)
	var url *url.URL
	url, _ = url.Parse("https://golang.org/")
	var cookies []*http.Cookie
	cookie := &http.Cookie{
		Name:  "cname",
		Value: "cvalue",
		Path:  "/",
	}
	cookies = append(cookies, cookie)
	cj.SetCookies(url, cookies)
	client.Jar = cj
	body := ""
	req, _ := http.NewRequest("GET", url.String(), strings.NewReader(body))
	dump, _ := httputil.DumpRequestOut(req, true)
	fmt.Println(string(dump))
}

@bradfitz bradfitz changed the title httputil.DumpRequestOut excluding Cookie header net/http/httputil: DumpRequestOut excluding Cookie header Nov 15, 2017
@caffeinejolt
Copy link
Author

Sorry - upon further investigation.. it does show the Cookie header - but only if you call httputil.DumpRequestOut after executing the request and getting the response - which is fine. I thought httputil.DumpRequestOut should know what headers it was going to send before sending them, but it does not work that way with a cookie jar evidently.

@golang golang locked and limited conversation to collaborators Nov 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants