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

No need match all c.allowedHeaders every time #95

Merged
merged 1 commit into from Mar 18, 2020
Merged

Conversation

yyonghe
Copy link
Contributor

@yyonghe yyonghe commented Mar 17, 2020

No need match all c.allowedHeaders every time.

@rs
Copy link
Owner

rs commented Mar 17, 2020

Please add context, you comment does not seem to match what your change is doing.

@yyonghe
Copy link
Contributor Author

yyonghe commented Mar 18, 2020

In function areHeadersAllowed(), when checking headers, if we've matched, we can break the for loop.

func (c *Cors) areHeadersAllowed(requestedHeaders []string) bool {
	if c.allowedHeadersAll || len(requestedHeaders) == 0 {
		return true
	}
	for _, header := range requestedHeaders {
		header = http.CanonicalHeaderKey(header)
		found := false
		for _, h := range c.allowedHeaders {
			if h == header {
				found = true
				break // added this line
			}
		}
		if !found {
			return false
		}
	}
	return true
}

@rs rs merged commit d4dacab into rs:master Mar 18, 2020
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

Successfully merging this pull request may close these issues.

None yet

2 participants