-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[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
Showing
2 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters