# The fetch returns the token of a "Bearer" authorization, either from the
# Authorization header or from the header given as argument. For the custom
# header, the value must be the "Bearer" scheme followed by at least one
-# space and the token. When the custom header is absent, nothing is found,
-# so that the Authorization header is checked by the next rule.
+# space and the token, whatever the token length. In particular a token
+# of 6 characters, as long as the word "Bearer" itself, must be found, and
+# a lone "Bearer" without any token is not a Bearer authorization. When the
+# custom header is absent, nothing is found, so that the Authorization
+# header is checked by the next rule.
feature ignore_unknown_macro
expect resp.status == 200
expect resp.http.tok == "a"
+ txreq -hdr "x-tok: Bearer abcdef"
+ rxresp
+ expect resp.status == 200
+ expect resp.http.tok == "abcdef"
+
txreq -hdr "x-tok: Bearer abcdefg"
rxresp
expect resp.status == 200
expect resp.status == 200
expect resp.http.tok == "xyz123"
- # another scheme
+ # no token, or another scheme
+ txreq -hdr "x-tok: Bearer"
+ rxresp
+ expect resp.status == 404
+
txreq -hdr "x-tok: Basic abcdef"
rxresp
expect resp.status == 404
ctx.blk = NULL;
if (http_find_header(htx, hdr_name, &ctx, 0)) {
+ struct ist value = ctx.value;
struct ist type = istsplit(&ctx.value, ' ');
/* no space was found or the space is the first character or no "Bearer" method */
- if (!istlen(type) || istlen(type) == istlen(ctx.value) || !isteqi(type, ist("Bearer")))
+ if (!istlen(type) || istlen(type) == istlen(value) || !isteqi(type, ist("Bearer")))
return 0;
/* There must be "at least" one space character between