Skip to content

Commit

Permalink
Refactor to use strings.EqualFold (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear committed Aug 3, 2023
1 parent fc86f52 commit 8aa5d6c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion request/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (e BearerExtractor) ExtractToken(req *http.Request) (string, error) {
tokenHeader := req.Header.Get("Authorization")
// The usual convention is for "Bearer" to be title-cased. However, there's no
// strict rule around this, and it's best to follow the robustness principle here.
if len(tokenHeader) < 7 || !strings.HasPrefix(strings.ToLower(tokenHeader[:7]), "bearer ") {
if len(tokenHeader) < 7 || !strings.EqualFold(tokenHeader[:7], "bearer ") {
return "", ErrNoTokenInRequest
}
return tokenHeader[7:], nil
Expand Down
2 changes: 1 addition & 1 deletion request/oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
// Strips 'Bearer ' prefix from bearer token string
func stripBearerPrefixFromTokenString(tok string) (string, error) {
// Should be a bearer token
if len(tok) > 6 && strings.ToUpper(tok[0:7]) == "BEARER " {
if len(tok) > 6 && strings.EqualFold(tok[:7], "bearer ") {
return tok[7:], nil
}
return tok, nil
Expand Down

0 comments on commit 8aa5d6c

Please sign in to comment.