Skip to content

Commit

Permalink
Disable noisy log warning
Browse files Browse the repository at this point in the history
  • Loading branch information
turt2live committed Aug 20, 2023
1 parent 157ec5d commit c2bd899
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions util/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,18 @@ import (
"net/http"
"net/url"
"strings"

"github.com/sirupsen/logrus"
)

func GetAccessTokenFromRequest(request *http.Request) string {
token := request.Header.Get("Authorization")

if token != "" {
if !strings.HasPrefix(token, "Bearer") {
logrus.Warn("Invalid Authorization header observed: expected a Bearer token, got something else")
if !strings.HasPrefix(token, "Bearer ") { // including space
// It's probably an X-Matrix authentication header (federation)
//logrus.Warn("Invalid Authorization header observed: expected a Bearer token, got something else")
return ""
}
if len(token) > 7 {
// "Bearer <token>"
return token[7:]
}
return token[len("Bearer "):] // including space
}

return request.URL.Query().Get("access_token")
Expand Down

0 comments on commit c2bd899

Please sign in to comment.