Skip to content

Commit 8026149

Browse files
committed
refactor(middleware): simplify authorization token parsing
• Replaces strings.Split with strings.Fields for clarity • Enhances readability by using strings.EqualFold for case-insensitive comparison
1 parent 2b71198 commit 8026149

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

middleware/token.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ func StoreWebToken() func(http.Handler) http.Handler {
2525
return func(next http.Handler) http.Handler {
2626
return http.HandlerFunc(func(responseWriter http.ResponseWriter, request *http.Request) {
2727
ctx := request.Context()
28-
auth := strings.Split(request.Header.Get(headers.Authorization), " ")
29-
if len(auth) > 1 && strings.ToUpper(auth[0]) == tokenAuthPrefix {
30-
ctx = pmcontext.AddWebTokenToContext(ctx, auth[1], signatureAlgorithms)
28+
tokens := strings.Fields(request.Header.Get(headers.Authorization))
29+
if len(tokens) == 2 && strings.EqualFold(tokens[0], tokenAuthPrefix) {
30+
ctx = pmcontext.AddWebTokenToContext(ctx, tokens[1], signatureAlgorithms)
3131
}
3232

3333
next.ServeHTTP(responseWriter, request.WithContext(ctx))

0 commit comments

Comments
 (0)