Proposal to Optimize JWT Plugin by Replacing ngx.re.gmatch
with string.sub in retrieve_tokens
func
#13378
dingjiayi
started this conversation in
Ideas and feature requests
Replies: 1 comment 4 replies
-
It can be considered in general. It needs to be functionally equivalent to the current solution, however. Your proposal only works if there is one space between the "[Bb]earer" prefix and the token, where the original allows one or more whitespace characters. You are invited to providing a pull request with your proposed changes. Please refer to our contributor guidelines to learn. |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello Kong Community,
I hope this message finds you well.
I have been working with the JWT plugin in the Kong repo and noticed that the current implementation uses
ngx.re.gmatch(token_header, "\\s*[Bb]earer\\s+(.+)")
to extract the token from the authorization header. While this approach is effective, I believe it can be optimized further.In my local tests, I found that using the
string.sub
function instead ofngx.re.gmatch
improves performance.Here is my testing process to validate this optimization:
I generated a large number of JWT tokens.
I iterated over all the tokens and called the retrieve_tokens_from_authorization function to extract the token.
I measured the time taken for step 2 using both
ngx.re.gmatch
andstring.sub
implementations of the retrieve_tokens_from_authorization function.The local test data is as follows:
I open this discussion on whether this optimization can be considered for the JWT plugin.
Beta Was this translation helpful? Give feedback.
All reactions