Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORS: the middleware needlessly compiles the same regexps during each of its invocations #2708

Closed
3 tasks done
jub0bs opened this issue Nov 21, 2024 · 1 comment
Closed
3 tasks done

Comments

@jub0bs
Copy link

jub0bs commented Nov 21, 2024

Issue Description

The CORS middleware currently recompiles the same regexps over and over during each of its invocations. However, for performance, compiling regexps on the hot path should be avoided when possible.

In this case, the regexps could be compiled once and for all during middleware initialisation. The following line

allowOriginPatterns := []string{}

could advantageously be replaced by

var allowOriginRegexp []*regexp.Regexp

and the rest of the necessary changes would flow from this simple change.

Checklist

  • Dependencies installed
  • No typos
  • Searched existing issues and docs

Expected behaviour

No regexp compilation on the hot path.

Actual behaviour

Regexp compilation on the hot path.

Version/commit

v4.12.0

@aldas
Copy link
Contributor

aldas commented Nov 22, 2024

Thanks for noticing. #2709 reworks that part

@aldas aldas closed this as completed Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants