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

request.Response.Header.Get(... resulting error nil pointer dereference #40930

Closed
bokunodev opened this issue Aug 20, 2020 · 2 comments
Closed

request.Response.Header.Get(... resulting error nil pointer dereference #40930

bokunodev opened this issue Aug 20, 2020 · 2 comments

Comments

@bokunodev
Copy link

@bokunodev bokunodev commented Aug 20, 2020

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

$ go version
go version go1.15 linux/arm64

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
GO111MODULE=""
GOARCH="arm64"
GOBIN="/home/bokuno/go/go/bin"
GOCACHE="/home/bokuno/.cache/go-build"
GOENV="/home/bokuno/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/bokuno/go/workspace/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/bokuno/go/workspace"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,https://index.golang.org,https://gocenter.io,https://athens.azurefd.net,direct"
GOROOT="/home/bokuno/go/go"
GOSUMDB="sum.golang.org"
GOTMPDIR="/tmp"
GOTOOLDIR="/home/bokuno/go/go/pkg/tool/linux_arm64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="0"
GOMOD="/home/bokuno/go/workspace/go-down/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS="-g -O2"
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build066285280=/tmp/go-build -gno-record-gcc-switches"

What did you do?

i tried to access response.Header.Get within function that accept pointer to http.Request as argument.
but, resulting error nil ponter dereference.
where did the pointer go ?
i am new in Go and sorry for my bad english.

if !(ranges && length && response.ContentLength < chunk+1) {
	ch := make(StreamChan, 1)
	name := getName(request.Response.Header.Get(ContentDisposition), // error
		request.URL)
	go downloadSingle(request, ch)
	return name, ch
}

What did you expect to see?

nothing

What did you see instead?

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x38 pc=0x1fa468]

goroutine 1 [running]:
go-down/network.Download(0x4000104c30, 0x4000162000, 0x272393, 0x3, 0xffffff7a86f6)
/home/bokuno/go/workspace/go-down/network/download.go:47 +0x128
main.main()
/home/bokuno/go/workspace/go-down/cmd/main.go:42 +0x124

@bokunodev bokunodev closed this Aug 20, 2020
@foobar1221
Copy link

@foobar1221 foobar1221 commented Sep 30, 2020

Hi @bokunodev ,

I am also facing similar issue with response.Header.Get, how did you managed to fix it ?

@bokunodev
Copy link
Author

@bokunodev bokunodev commented Sep 30, 2020

Hi @foobar1221 I misread the comments. the documentation is clear.

// Response is the redirect response which caused this request
// be created. ___ This field is only populated during client redirects. ___
   Response *Response

// to be created. This field is only populated during client

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.