Skip to content

Commit db86f12

Browse files
committed
clarify in documentation cut-prefix meaning for middlewares header extraction
1 parent c4bf656 commit db86f12

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

middleware/extractor.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ func createExtractors(lookups string, authScheme string) ([]ValuesExtractor, err
6666
}
6767

6868
// valuesFromHeader returns a functions that extracts values from the request header.
69+
// valuePrefix is parameter to remove first part (prefix) of the extracted value. This is useful if header value has static
70+
// prefix like `Authorization: <auth-scheme> <authorisation-parameters>` where part that we want to remove is `<auth-scheme> `
71+
// note the space at the end. In case of basic authentication `Authorization: Basic <credentials>` prefix we want to remove
72+
// is `Basic `. In case of JWT tokens `Authorization: Bearer <token>` prefix is `Bearer `.
73+
// If prefix is left empty the whole value is returned.
6974
func valuesFromHeader(header string, valuePrefix string) ValuesExtractor {
7075
prefixLen := len(valuePrefix)
7176
// standard library parses http.Request header keys in canonical form but we may provide something else so fix this

middleware/jwt.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ type (
6969
// Optional. Default value "header:Authorization".
7070
// Possible values:
7171
// - "header:<name>" or "header:<name>:<cut-prefix>"
72+
// `<cut-prefix>` is argument value to cut/trim prefix of the extracted value. This is useful if header
73+
// value has static prefix like `Authorization: <auth-scheme> <authorisation-parameters>` where part that we
74+
// want to cut is `<auth-scheme> ` note the space at the end.
75+
// In case of JWT tokens `Authorization: Bearer <token>` prefix we cut is `Bearer `.
76+
// If prefix is left empty the whole value is returned.
7277
// - "query:<name>"
7378
// - "param:<name>"
7479
// - "cookie:<name>"

middleware/key_auth.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ type (
1717
// Optional. Default value "header:Authorization".
1818
// Possible values:
1919
// - "header:<name>" or "header:<name>:<cut-prefix>"
20+
// `<cut-prefix>` is argument value to cut/trim prefix of the extracted value. This is useful if header
21+
// value has static prefix like `Authorization: <auth-scheme> <authorisation-parameters>` where part that we
22+
// want to cut is `<auth-scheme> ` note the space at the end.
23+
// In case of basic authentication `Authorization: Basic <credentials>` prefix we want to remove is `Basic `.
2024
// - "query:<name>"
2125
// - "form:<name>"
2226
// - "cookie:<name>"

0 commit comments

Comments
 (0)