MCPcopy Create free account
hub / github.com/Apress/pro-go / HTTPSRedirect

Function HTTPSRedirect

24 - HTTP Servers/httpserver/main.go:19–27  ·  view source on GitHub ↗
(writer http.ResponseWriter, 
        request *http.Request)

Source from the content-addressed store, hash-verified

17}
18
19func HTTPSRedirect(writer http.ResponseWriter,
20 request *http.Request) {
21 host := strings.Split(request.Host, ":")[0]
22 target := "https://" + host + ":5500" + request.URL.Path
23 if len(request.URL.RawQuery) > 0 {
24 target += "?" + request.URL.RawQuery
25 }
26 http.Redirect(writer, request, target, http.StatusTemporaryRedirect)
27}
28
29func main() {
30 http.Handle("/message", StringHandler{ "Hello, World"})

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected