vcs-test: add a /insecure handler that redirects to plain HTTP
Updates golang/go#29591
Change-Id: I5c9899a475ba7521b49c3eef2679c104df0ae0f7
Reviewed-on: https://go-review.googlesource.com/c/build/+/167710
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/vcs-test/vcweb/insecure.go b/vcs-test/vcweb/insecure.go
new file mode 100644
index 0000000..9c64097
--- /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 781dced..ad15a48 100644
--- a/vcs-test/vcweb/main.go
+++ b/vcs-test/vcweb/main.go
@@ -67,6 +67,7 @@
http.Handle("/svn/", svnHandler())
http.Handle("/fossil/", fossilHandler())
http.Handle("/bzr/", bzrHandler())
+ http.Handle("/insecure/", insecureRedirectHandler())
handler := logger(http.HandlerFunc(loadAndHandle))