diff --git a/vcs-test/vcweb/insecure.go b/vcs-test/vcweb/insecure.go new file mode 100644 index 0000000000..9c64097562 --- /dev/null +++ b/vcs-test/vcweb/insecure.go @@ -0,0 +1,30 @@ +// Copyright 2019 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build linux + +package main + +import ( + "net/http" + "strings" +) + +func insecureRedirectHandler() http.Handler { + return http.HandlerFunc(insecureRedirectDispatch) +} + +func insecureRedirectDispatch(w http.ResponseWriter, r *http.Request) { + if !strings.HasPrefix(r.URL.Path, "/insecure/") { + http.Error(w, "path does not start with /insecure/", http.StatusInternalServerError) + } + + url := *r.URL + url.Scheme = "http" // not "https" + if url.Host == "" { + url.Host = r.Host + } + url.Path = strings.TrimPrefix(url.Path, "/insecure") + http.Redirect(w, r, url.String(), http.StatusMovedPermanently) +} diff --git a/vcs-test/vcweb/main.go b/vcs-test/vcweb/main.go index 781dcedd3f..ad15a48758 100644 --- a/vcs-test/vcweb/main.go +++ b/vcs-test/vcweb/main.go @@ -67,6 +67,7 @@ func main() { http.Handle("/svn/", svnHandler()) http.Handle("/fossil/", fossilHandler()) http.Handle("/bzr/", bzrHandler()) + http.Handle("/insecure/", insecureRedirectHandler()) handler := logger(http.HandlerFunc(loadAndHandle))