forked from coder/coder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequest.go
More file actions
30 lines (25 loc) · 652 Bytes
/
Copy pathrequest.go
File metadata and controls
30 lines (25 loc) · 652 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package httpapi
import "net/http"
const (
// XForwardedHostHeader is a header used by proxies to indicate the
// original host of the request.
XForwardedHostHeader = "X-Forwarded-Host"
)
// RequestHost returns the name of the host from the request. It prioritizes
// 'X-Forwarded-Host' over r.Host since most requests are being proxied.
func RequestHost(r *http.Request) string {
host := r.Header.Get(XForwardedHostHeader)
if host != "" {
return host
}
return r.Host
}
func IsWebsocketUpgrade(r *http.Request) bool {
vs := r.Header.Values("Upgrade")
for _, v := range vs {
if v == "websocket" {
return true
}
}
return false
}