net/http: on 301 redirects, DELETE method is transformed into GET #21469
Comments
#13994 seems similar (other issues linked in this comment #13994 (comment)) Seems like a special case of the redirect behavior for DELETE |
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/ We also documented this change in the release notes here https://golang.org/doc/go1.8#minor_library_changes Hope this makes sense. |
Do you mean I should change server to return 307/308 instead of 301 on DELETE? |
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. |
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. |
I was able to modify the server to redirection to 307/308 and able to work with 1.9rc2. Thanks. |
Awesome, good to know! |
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.

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.
The text was updated successfully, but these errors were encountered: