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

DisableCompression=true not work, the request header still has Accept-Encoding: gzip #29607

Closed
andymacau853 opened this issue Jan 8, 2019 · 3 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@andymacau853
Copy link

andymacau853 commented Jan 8, 2019

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?

I have set DisableCompression=true but not work, the request header still has added Accept-Encoding: gzip, bug??

res, err := (&http.Client{
Transport: &http.Transport{
DialContext: func(ctx context.Context, netw, addr string) (net.Conn, error) {
conn, err := net.DialTimeout(netw, addr, time.Duration(job[taskID].HttpConnectTimeout)*time.Millisecond)
if err != nil {
return nil, err
}
err = conn.SetReadDeadline(time.Now().Add(time.Duration(job[taskID].HttpReadTimeout) * time.Millisecond))
if err != nil {
return nil, err
}
err = conn.SetWriteDeadline(time.Now().Add(time.Duration(job[taskID].HttpWriteTimeout) * time.Millisecond))
if err != nil {
return nil, err
}
return conn, nil
},
TLSClientConfig: &tls.Config{
InsecureSkipVerify: job[taskID].HttpInsecureSkipVerify,
},
DisableCompression: true,
},
}).Do(req)

What did you expect to see?

No auto added Accept-Encoding: gzip, then the server will response no gzip content:
GET / HTTP/1.1
Host: www.jobs.af
User-Agent: Go-http-client/1.1

What did you see instead?

Auto added Accept-Encoding: gzip, it seems that DisableCompression not work.
GET / HTTP/1.1
Host: www.jobs.af
User-Agent: Go-http-client/1.1
Accept-Encoding: gzip

@agnivade
Copy link
Contributor

agnivade commented Jan 8, 2019

Hi @andymacau853- Kindly show us a working code sample which shows this issue. Thanks.

@julieqiu julieqiu added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jan 8, 2019
@agnivade
Copy link
Contributor

agnivade commented Jan 9, 2019

I am unable to reproduce this -

package main

import (
	"context"
	"io"
	"io/ioutil"
	"log"
	"net"
	"net/http"
	"net/http/httputil"
	"time"
)

func main() {
	helloHandler := func(w http.ResponseWriter, req *http.Request) {
		buf, err := httputil.DumpRequest(req, false)
		if err != nil {
			log.Println(err)
			return
		}
		log.Printf("%s", buf)
		io.WriteString(w, "Hello, world!\n")
	}

	http.HandleFunc("/hello", helloHandler)
	go func() {
		log.Fatal(http.ListenAndServe(":8080", nil))
	}()

	res, err := (&http.Client{
		Transport: &http.Transport{
			DialContext: func(ctx context.Context, netw, addr string) (net.Conn, error) {
				conn, err := net.DialTimeout(netw, addr, time.Duration(1*time.Second))
				if err != nil {
					return nil, err
				}
				err = conn.SetReadDeadline(time.Now().Add(time.Duration(1 * time.Second)))
				if err != nil {
					return nil, err
				}
				err = conn.SetWriteDeadline(time.Now().Add(time.Duration(1 * time.Second)))
				if err != nil {
					return nil, err
				}
				return conn, nil
			},
			DisableCompression: true,
		},
	}).Get("http://localhost:8080/hello")
	if err != nil {
		log.Println(err)
		return
	}
	defer res.Body.Close()
	buf, err := ioutil.ReadAll(res.Body)
	if err != nil {
		log.Println(err)
		return
	}
	log.Printf("%s", buf)

	select {}
}
2019/01/09 14:59:07 GET /hello HTTP/1.1
Host: localhost:8080
User-Agent: Go-http-client/1.1

2019/01/09 14:59:07 Hello, world!
^Csignal: interrupt

Can you show us the Request that you are passing ?

@gopherbot
Copy link
Contributor

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@golang golang locked and limited conversation to collaborators Feb 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants