...
1 package web
2
3 import (
4 "net/http"
5 "net/url"
6 )
7
8
9
10 func RelativeEndpoint(request *http.Request, endpoint string) string {
11 var result string
12 proto := "http"
13 host := request.Host
14
15
16 if request.TLS != nil {
17 proto = "https"
18 }
19
20
21
22 if specifiedProto := request.Header.Get("X-Forwarded-Proto"); specifiedProto != "" {
23 proto = specifiedProto
24 }
25
26
27
28 if request.Host == "" {
29 host = "localhost"
30 }
31
32 resultUrl := url.URL{Scheme: proto, Host: host, Path: endpoint}
33 result = resultUrl.String()
34
35 return result
36 }
37
View as plain text