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: on 301 redirects, DELETE method is transformed into GET #21469

Closed
paravmellanox opened this issue Aug 16, 2017 · 7 comments
Closed

Comments

@paravmellanox
Copy link

paravmellanox commented Aug 16, 2017

Please answer these questions before submitting your issue. Thanks!

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

go1.9rc2

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/usr/golang"
GORACE=""
GOROOT="/root/sdk/go1.9rc2"
GOTOOLDIR="/root/sdk/go1.9rc2/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build696746158=/tmp/go-build -gno-record-gcc-switches"
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"

What did you do?

perform http.client DELETE request to a bucket.

client running below program to delete results in DELETE, followed by GET method when server responds with 301 response code.
client := &http.Client{}
req, err := http.NewRequest("DELETE", url, nil)
if err != nil {
return err
}
rsp, err := client.Do(req)

What did you expect to see?

after receiving 301 response, I expect to see http client code issuing DELETE.

What did you see instead?

I see GET command issue to the URL by the http.client.
go_client_rc1 9rc1_delete_error

curl -i -L -X DELETE http://127.0.0.1:8080/v1/osd-volumes/8b91b28ddb7148a3add6b3d7872d9bb7 has worked fine where I see DELETE, 301, DELETE, 200 sequence.

@jaredborner
Copy link

#13994 seems similar (other issues linked in this comment #13994 (comment))

Seems like a special case of the redirect behavior for DELETE

@odeke-em odeke-em changed the title http.Client doesnt perform DELETE correctly, issues GET on receiving 301 response code, instead of DELETE net/http: on 301 redirects, DELETE method is transformed into GET Aug 16, 2017
@odeke-em
Copy link
Member

Hello @paravmellanox, thanks for the question.

So @bradfitz and I collaborated on fixing the redirect behavior at our weekend hackathons during the Go1.8 cycle in late September 2016, and I then implemented it with 7db996e, we used Google Doc https://docs.google.com/document/d/1LnWicNarwSdVWQ5RcgUOdHEGVcdR--Lravn6G0Hkg6c/edit?usp=sharing as the common scratch paper.

The rationale for 301/302/303 status converts converting all methods to GET is that we need to match what historically browsers have done (despite being arguably broken behavior); the 303 unconditionally redirects to GET and 301/302 do the same. Our reference was https://blogs.msdn.microsoft.com/ieinternals/2011/08/19/http-methods-and-redirect-status-codes/
If you'd like to preserve the method, please use 307/308.

We also documented this change in the release notes here https://golang.org/doc/go1.8#minor_library_changes
screen shot 2017-08-16 at 12 42 23 pm

Hope this makes sense.

@paravmellanox
Copy link
Author

Do you mean I should change server to return 307/308 instead of 301 on DELETE?

@odeke-em
Copy link
Member

Yes in deed, that's what I am saying: if you'd like to preserve the method, please use 307/308, where 307 is a Temporary Redirect and 308 is a Permanent Redirect.

@paravmellanox
Copy link
Author

ok. Got it. Let me check server code. libcurl, curl utility worked (were able to handle it), so was wondering if http package can do or not.

@paravmellanox
Copy link
Author

I was able to modify the server to redirection to 307/308 and able to work with 1.9rc2. Thanks.

@odeke-em
Copy link
Member

Awesome, good to know!

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

4 participants