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

Missing header "content-length" when http get request with redirecting #40787

Closed
elftech opened this issue Aug 14, 2020 · 5 comments
Closed

Missing header "content-length" when http get request with redirecting #40787

elftech opened this issue Aug 14, 2020 · 5 comments

Comments

@elftech
Copy link

elftech commented Aug 14, 2020

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

$ go version
go version go1.13.6 linux/amd64

Does this issue reproduce with the latest release?

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

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOROOT="/usr/lib/golang"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build778696983=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I use to http.Client to get a file and print response headers and no content length found. But it can be found using comand "curl -I -L "

       var host string

        req, _ := http.NewRequest("GET", src_url_old, nil) 
        req.Host = host 

        glog.Info(PREFIX, "SRC_URL: ", src_url_old)

        resp, err := srcClient.Do(req)

        if err == nil && resp.StatusCode == http.StatusOK {

            file_size := []string{"0"}
            ok := false
            if file_size, ok = resp.Header["content-length"]; !ok {
                if file_size, ok = resp.Header["Content-length"]; !ok {
                    file_size, ok = resp.Header["Content-Length"]
                    _ = ok
                }
            }
            //Output headers
            glog.Info("resp.Header: ", resp.Header)
            glog.Flush()

What did you expect to see?

All headers the redirected location has.
curl -I -L < src_url_old >

HTTP/1.1 200 
Server: openresty
Date: Fri, 14 Aug 2020 07:49:11 GMT
Content-Type: image/png
Content-Length: 64952
Connection: keep-alive
Vary: Accept-Encoding
Set-Cookie: accessproxy_session=6435ad5d-cbc0-4f12-93ff-fefe72fa436a; Path=/; Expires=Sat, 15-Aug-20 07:49:11 GMT; HttpOnly; Domain=XXXX.corp.com
Content-disposition: inline; filename=6f7762ca97b3aa4bdbc0723cd215069b1d18110f1aa13747e72374aef6b88fc4.png
Expires: Fri, 21 Aug 2020 07:49:11 GMT
Cache-Control: max-age=604800
X-Proxy-Cache: HIT
Accept-Ranges: bytes
Content-Security-Policy: upgrade-insecure-requests

What did you see instead?

glog outputs following headers below. Just no content-length

Cache-Control:[max-age=604800]
Connection:[keep-alive] 
Content-Disposition:[inline; filename=6f7762ca97b3aa4bdbc0723cd215069b1d18110f1aa13747e72374aef6b88fc4.png] 
Content-Security-Policy:[upgrade-insecure-requests] 
Content-Type:[image/png] 
Date:[Fri, 14 Aug 2020 06:32:17 GMT] 
Expires:[Fri, 21 Aug 2020 06:32:17 GMT] 
Server:[openresty] 
Set-Cookie:[accessproxy_session=f34b6f83-082c-431a-9366-8c090adae5cb; Path=/; Expires=Sat, 15-Aug-20 06:32:17 GMT; HttpOnly; Domain=XXX.corp.com] Vary:[Accept-Encoding]
X-Proxy-Cache:[MISS]]
@davecheney davecheney added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Aug 14, 2020
@elftech
Copy link
Author

elftech commented Aug 14, 2020

@elftech what is the status code that the server responds with?

http.StatusOK

@davecheney
Copy link
Contributor

My bad, I missed that the code was already checking for this.

I think you should ask your question on one of the other forums. I'm pretty confident this is not a Go bug and, while may not be what you want, is working as intended.

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For asking questions, see:

@elftech
Copy link
Author

elftech commented Aug 14, 2020

My bad, I missed that the code was already checking for this.

I think you should ask your question on one of the other forums. I'm pretty confident this is not a Go bug and, while may not be what you want, is working as intended.

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For asking questions, see:

3ks! I thought is might be a bug of http library. But I should ask for helper on these websites you providers. I'll try.

@davecheney
Copy link
Contributor

It is likely that the http.Response type is slightly cooked before you get it. See https://godoc.org/net/http#Response ContentLength.

@elftech elftech closed this as completed Aug 15, 2020
@elftech
Copy link
Author

elftech commented Aug 15, 2020

Find a way to workaround redirecting

@golang golang locked and limited conversation to collaborators Aug 15, 2021
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

3 participants