redirectWithQuery responds with a given redirect code, preserving query parameters in the redirect URL. It does not convert relative paths to absolute paths like http.Redirect does, so that HTTPServerArgs.Handlers can generate relative redirects that work with the external prefixing.
(path string, code int)
| 221 | // absolute paths like http.Redirect does, so that HTTPServerArgs.Handlers can |
| 222 | // generate relative redirects that work with the external prefixing. |
| 223 | func redirectWithQuery(path string, code int) http.HandlerFunc { |
| 224 | return func(w http.ResponseWriter, r *http.Request) { |
| 225 | pathWithQuery := &gourl.URL{Path: path, RawQuery: r.URL.RawQuery} |
| 226 | w.Header().Set("Location", pathWithQuery.String()) |
| 227 | w.WriteHeader(code) |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | func isLocalhost(host string) bool { |
| 232 | return slices.Contains([]string{"localhost", "127.0.0.1", "[::1]", "::1"}, host) |
no test coverage detected
searching dependent graphs…