Skip to content

Commit

Permalink
vcs-test: add a /insecure handler that redirects to plain HTTP
Browse files Browse the repository at this point in the history
Updates golang/go#29591

Change-Id: I5c9899a475ba7521b49c3eef2679c104df0ae0f7
Reviewed-on: https://go-review.googlesource.com/c/build/+/167710
Run-TryBot: Bryan C. Mills <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Brad Fitzpatrick <[email protected]>
  • Loading branch information
Bryan C. Mills committed Mar 14, 2019
1 parent 83c6b6a commit 097ea78
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
30 changes: 30 additions & 0 deletions vcs-test/vcweb/insecure.go
Original file line number Diff line number Diff line change
@@ -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)
}
1 change: 1 addition & 0 deletions vcs-test/vcweb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down

0 comments on commit 097ea78

Please sign in to comment.