func redirect()

in cmd/redirector/main.go [55:94]


func redirect(w http.ResponseWriter, req *http.Request) {
	if req.Method == http.MethodPost {
		manualRedirect(w, req)
		return
	}
	if req.Method != http.MethodGet && req.Method != http.MethodHead {
		w.WriteHeader(http.StatusMethodNotAllowed)
		fmt.Fprintf(w, "method %s not allowed", req.Method)
		return
	}

	repoParam := req.URL.Query().Get(paramRepo)
	referer := req.Header.Get(hdrReferer)

	// TODO(ahmetb): remove once https://github.community/t/chrome-85-breaks-referer/130039 is fixed
	if referer == "https://github.com/" && repoParam == "" {
		showRedirectForm(w, req)
		return
	}

	var repo repoRef
	if repoParam != "" {
		repo = customRepoRef{req.URL.Query()}
	} else {
		if referer == "" {
			w.WriteHeader(http.StatusBadRequest)
			fmt.Fprintf(w, "Cannot infer which repository to deploy (%s header was not present).\n", hdrReferer)
			fmt.Fprintln(w, "Go back, and click the 'Run on Google Cloud' button directly from the repository page.")
			return
		}
		r, err := parseReferer(referer, availableExtractors)
		if err != nil {
			w.WriteHeader(http.StatusBadRequest)
			fmt.Fprintf(w, errors.Wrapf(err, "failed to parse %s header", hdrReferer).Error())
			return
		}
		repo = r
	}
	doRedirect(w, repo, req.URL.Query())
}