Skip to content

Commit 8aa5d6c

Browse files
authored
Refactor to use strings.EqualFold (#329)
1 parent fc86f52 commit 8aa5d6c

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

request/extractor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func (e BearerExtractor) ExtractToken(req *http.Request) (string, error) {
9090
tokenHeader := req.Header.Get("Authorization")
9191
// The usual convention is for "Bearer" to be title-cased. However, there's no
9292
// strict rule around this, and it's best to follow the robustness principle here.
93-
if len(tokenHeader) < 7 || !strings.HasPrefix(strings.ToLower(tokenHeader[:7]), "bearer ") {
93+
if len(tokenHeader) < 7 || !strings.EqualFold(tokenHeader[:7], "bearer ") {
9494
return "", ErrNoTokenInRequest
9595
}
9696
return tokenHeader[7:], nil

request/oauth2.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
// Strips 'Bearer ' prefix from bearer token string
88
func stripBearerPrefixFromTokenString(tok string) (string, error) {
99
// Should be a bearer token
10-
if len(tok) > 6 && strings.ToUpper(tok[0:7]) == "BEARER " {
10+
if len(tok) > 6 && strings.EqualFold(tok[:7], "bearer ") {
1111
return tok[7:], nil
1212
}
1313
return tok, nil

0 commit comments

Comments
 (0)