Skip to content

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

Description

@jub0bs

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions