mirror of
https://github.com/golang/go.git
synced 2025-05-05 23:53:05 +00:00
godoc/dl: also serve go-import meta tags at golang.org/dl for cmd/go
Updates golang/go#23223 Change-Id: Iacecbb5e095fd3d6acb3f8e1fb238db63d1e0b6d Reviewed-on: https://go-review.googlesource.com/125195 Reviewed-by: Andrew Bonventre <andybons@golang.org>
This commit is contained in:
parent
827f47db85
commit
99195f4d4f
@ -41,7 +41,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func RegisterHandlers(mux *http.ServeMux) {
|
func RegisterHandlers(mux *http.ServeMux) {
|
||||||
mux.Handle("/dl", http.RedirectHandler("/dl/", http.StatusFound))
|
mux.HandleFunc("/dl", getHandler)
|
||||||
mux.HandleFunc("/dl/", getHandler) // also serves listHandler
|
mux.HandleFunc("/dl/", getHandler) // also serves listHandler
|
||||||
mux.HandleFunc("/dl/upload", uploadHandler)
|
mux.HandleFunc("/dl/upload", uploadHandler)
|
||||||
mux.HandleFunc("/dl/init", initHandler)
|
mux.HandleFunc("/dl/init", initHandler)
|
||||||
@ -428,6 +428,20 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getHandler(w http.ResponseWriter, r *http.Request) {
|
func getHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// For go get golang.org/dl/go1.x.y, we need to serve the
|
||||||
|
// same meta tags at /dl for cmd/go to validate against /dl/go1.x.y:
|
||||||
|
if r.URL.Path == "/dl" && (r.Method == "GET" || r.Method == "HEAD") && r.FormValue("go-get") == "1" {
|
||||||
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
|
fmt.Fprintf(w, `<!DOCTYPE html><html><head>
|
||||||
|
<meta name="go-import" content="golang.org/dl git https://go.googlesource.com/dl">
|
||||||
|
</head></html>`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if r.URL.Path == "/dl" {
|
||||||
|
http.Redirect(w, r, "/dl/", http.StatusFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
name := strings.TrimPrefix(r.URL.Path, "/dl/")
|
name := strings.TrimPrefix(r.URL.Path, "/dl/")
|
||||||
if name == "" {
|
if name == "" {
|
||||||
listHandler(w, r)
|
listHandler(w, r)
|
||||||
@ -438,11 +452,15 @@ func getHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if goGetRe.MatchString(name) {
|
if goGetRe.MatchString(name) {
|
||||||
|
var isGoGet bool
|
||||||
if r.Method == "GET" || r.Method == "HEAD" {
|
if r.Method == "GET" || r.Method == "HEAD" {
|
||||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
|
isGoGet = r.FormValue("go-get") == "1"
|
||||||
|
}
|
||||||
|
if !isGoGet {
|
||||||
|
w.Header().Set("Location", "https://golang.org/dl/#"+name)
|
||||||
|
w.WriteHeader(http.StatusFound)
|
||||||
}
|
}
|
||||||
w.Header().Set("Location", "https://golang.org/dl/#"+name)
|
|
||||||
w.WriteHeader(http.StatusFound)
|
|
||||||
fmt.Fprintf(w, `<!DOCTYPE html>
|
fmt.Fprintf(w, `<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user