1
0
mirror of https://github.com/golang/go synced 2024-11-18 13:44:48 -07:00

godoc/dl: serve "go get" meta for golang.org/dl/gotip

Change-Id: I05db10e9b3f4983d23af4dc5fd4cce9b3979e9c5
Reviewed-on: https://go-review.googlesource.com/c/153097
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Filippo Valsorda 2018-12-06 20:45:49 -05:00
parent 5f4a60f04f
commit 4d6773f6fa

View File

@ -137,9 +137,10 @@ func (h server) uploadHandler(w http.ResponseWriter, r *http.Request) {
} }
func (h server) getHandler(w http.ResponseWriter, r *http.Request) { func (h server) getHandler(w http.ResponseWriter, r *http.Request) {
// For go get golang.org/dl/go1.x.y, we need to serve the isGoGet := (r.Method == "GET" || r.Method == "HEAD") && r.FormValue("go-get") == "1"
// same meta tags at /dl for cmd/go to validate against /dl/go1.x.y: // For go get, we need to serve the same meta tags at /dl for cmd/go to
if r.URL.Path == "/dl" && (r.Method == "GET" || r.Method == "HEAD") && r.FormValue("go-get") == "1" { // validate against the import path.
if r.URL.Path == "/dl" && isGoGet {
w.Header().Set("Content-Type", "text/html; charset=utf-8") w.Header().Set("Content-Type", "text/html; charset=utf-8")
fmt.Fprintf(w, `<!DOCTYPE html><html><head> fmt.Fprintf(w, `<!DOCTYPE html><html><head>
<meta name="go-import" content="golang.org/dl git https://go.googlesource.com/dl"> <meta name="go-import" content="golang.org/dl git https://go.googlesource.com/dl">
@ -152,39 +153,37 @@ func (h server) getHandler(w http.ResponseWriter, r *http.Request) {
} }
name := strings.TrimPrefix(r.URL.Path, "/dl/") name := strings.TrimPrefix(r.URL.Path, "/dl/")
if name == "" { var redirectURL string
switch {
case name == "":
h.listHandler(w, r) h.listHandler(w, r)
return return
} case fileRe.MatchString(name):
if fileRe.MatchString(name) {
http.Redirect(w, r, downloadBaseURL+name, http.StatusFound) http.Redirect(w, r, downloadBaseURL+name, http.StatusFound)
return return
} case name == "gotip":
if goGetRe.MatchString(name) { redirectURL = "https://godoc.org/golang.org/dl/gotip"
var isGoGet bool case goGetRe.MatchString(name):
if r.Method == "GET" || r.Method == "HEAD" { redirectURL = "https://golang.org/dl/#" + name
w.Header().Set("Content-Type", "text/html; charset=utf-8") default:
isGoGet = r.FormValue("go-get") == "1" http.NotFound(w, r)
}
if !isGoGet {
w.Header().Set("Location", "https://golang.org/dl/#"+name)
w.WriteHeader(http.StatusFound)
}
fmt.Fprintf(w, `<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="go-import" content="golang.org/dl git https://go.googlesource.com/dl">
<meta http-equiv="refresh" content="0; url=https://golang.org/dl/#%s">
</head>
<body>
Nothing to see here; <a href="https://golang.org/dl/#%s">move along</a>.
</body>
</html>
`, html.EscapeString(name), html.EscapeString(name))
return return
} }
http.NotFound(w, r) w.Header().Set("Content-Type", "text/html; charset=utf-8")
if !isGoGet {
w.Header().Set("Location", redirectURL)
}
fmt.Fprintf(w, `<!DOCTYPE html>
<html>
<head>
<meta name="go-import" content="golang.org/dl git https://go.googlesource.com/dl">
<meta http-equiv="refresh" content="0; url=%s">
</head>
<body>
Nothing to see here; <a href="%s">move along</a>.
</body>
</html>
`, html.EscapeString(redirectURL), html.EscapeString(redirectURL))
} }
func (h server) initHandler(w http.ResponseWriter, r *http.Request) { func (h server) initHandler(w http.ResponseWriter, r *http.Request) {