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: 301 redirects to site with https to after a 303 redirect from a POST request don't work #21426

Closed
zhuqiuzhi opened this issue Aug 13, 2017 · 1 comment

Comments

Projects
None yet
3 participants
@zhuqiuzhi
Copy link

commented Aug 13, 2017

Please answer these questions before submitting your issue. Thanks!

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

go version go1.7.6 darwin/amd64
go version go1.6.4 darwin/amd64

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/zhuqiuzhi/work"
GORACE=""
GOROOT="/Users/zhuqiuzhi/.gvm/gos/go1.7.6"
GOTOOLDIR="/Users/zhuqiuzhi/.gvm/gos/go1.7.6/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/dc/q_v8vj2957s1k0krncnl26q40000gn/T/go-build403359302=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/zhuqiuzhi/work"
GORACE=""
GOROOT="/Users/zhuqiuzhi/.gvm/gos/go1.6.4"
GOTOOLDIR="/Users/zhuqiuzhi/.gvm/gos/go1.6.4/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT="1"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"

What did you do?

package main

import (
	"net/http"
	"net/http/httptest"
	"fmt"
)

func main() {
	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Location", "http://www.qiniu.com/")
		w.WriteHeader(http.StatusSeeOther)
	}))
	defer ts.Close()

	resp, err := http.Post(ts.URL,"multipart/form-data", nil)
	if err != nil {
		fmt.Printf("Post fail, ", err)
	}
	fmt.Println(resp.StatusCode)
	if resp.StatusCode != http.StatusOK {
		fmt.Printf("%v\n", resp.Header)
		fmt.Printf("Fail follow 301, https\n")
	} else {
		fmt.Println("OK")
	}
}

What did you expect to see?

200
OK

What did you see instead?

301
map[Connection:[keep-alive] Date:[Sun, 13 Aug 2017 12:33:51 GMT] X-Swift-Savetime:[Sun, 13 Aug 2017 12:33:51 GMT] Timing-Allow-Origin:[*] Eagleid:[7529f0cc15026276318052012e] Server:[Tengine] Content-Type:[text/html] Content-Length:[178] Location:[https://www.qiniu.com/] Via:[cache17.l2em21-1[31,301-0,M], cache8.l2em21-1[32,0], cache2.cn26[46,301-0,M], cache4.cn26[47,0]] X-Cache:[MISS TCP_MISS dirn:-2:-2] X-Swift-Cachetime:[0]]
Fail follow 301, https

@zhuqiuzhi zhuqiuzhi changed the title net/http: 301 redirects site with https to after a 303 redirect from a POST request don't work net/http: 301 redirects to site with https to after a 303 redirect from a POST request don't work Aug 13, 2017

@odeke-em

This comment has been minimized.

Copy link
Member

commented Aug 13, 2017

Hello there @zhuqiuzhi, this bug is fixed on Go1.8 and above, please update. It successfully redirects as you'll see in my screenshot below
screen shot 2017-08-13 at 12 50 27 pm

We worked on redirects with CLs https://go-review.googlesource.com/c/29852, https://go-review.googlesource.com/c/35633, https://go-review.googlesource.com/c/34657 and numerous other ones during the 1.8 cycle.

I'll close this issue, but please feel free to reopen if the problem persists. It'd also be nice to update since there are lots of bug fixes and great features that have been added since Go1.8; we'll soon be releasing Go1.9, which will mean that supporting Go1.6, Go1.7 is going to be even harder.

@odeke-em odeke-em closed this Aug 13, 2017

@golang golang locked and limited conversation to collaborators Aug 14, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.