mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add panic recovery middleware (#3687)
This commit is contained in:
@@ -0,0 +1,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
|
||||
}
|
||||
Reference in New Issue
Block a user