2024-09-16 09:10:04 +00:00
|
|
|
package auth
|
2021-07-30 10:20:07 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"net/textproto"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"golang.org/x/net/http/httpguts"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
connectionHeader = "Connection"
|
|
|
|
upgradeHeader = "Upgrade"
|
|
|
|
)
|
|
|
|
|
2024-09-27 09:18:05 +00:00
|
|
|
// RemoveConnectionHeaders removes hop-by-hop headers listed in the "Connection" header.
|
2021-07-30 10:20:07 +00:00
|
|
|
// See RFC 7230, section 6.1.
|
2024-09-27 09:18:05 +00:00
|
|
|
func RemoveConnectionHeaders(req *http.Request) {
|
|
|
|
var reqUpType string
|
|
|
|
if httpguts.HeaderValuesContainsToken(req.Header[connectionHeader], upgradeHeader) {
|
|
|
|
reqUpType = req.Header.Get(upgradeHeader)
|
2021-07-30 10:20:07 +00:00
|
|
|
}
|
|
|
|
|
2024-09-27 09:18:05 +00:00
|
|
|
for _, f := range req.Header[connectionHeader] {
|
2021-07-30 10:20:07 +00:00
|
|
|
for _, sf := range strings.Split(f, ",") {
|
|
|
|
if sf = textproto.TrimString(sf); sf != "" {
|
2024-09-27 09:18:05 +00:00
|
|
|
req.Header.Del(sf)
|
2021-07-30 10:20:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-09-27 09:18:05 +00:00
|
|
|
|
|
|
|
if reqUpType != "" {
|
|
|
|
req.Header.Set(connectionHeader, upgradeHeader)
|
|
|
|
req.Header.Set(upgradeHeader, reqUpType)
|
|
|
|
} else {
|
|
|
|
req.Header.Del(connectionHeader)
|
|
|
|
}
|
2021-07-30 10:20:07 +00:00
|
|
|
}
|