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

public method to check cors domain #115

Merged
merged 3 commits into from
Jun 7, 2021
Merged

public method to check cors domain #115

merged 3 commits into from
Jun 7, 2021

Conversation

alicebob
Copy link
Contributor

@alicebob alicebob commented Jun 7, 2021

Fixes #114.
Exposes the isOriginAllowed() function so it can be used in gorilla/websocket, this way:

    return &websocket.Upgrader{
        ReadBufferSize:  1024,
        WriteBufferSize: 1024,
        CheckOrigin:     c.OriginAllowed,
    }

cors.go Outdated
// check the Origin of a request. No origin at all is also allowed.
func (c *Cors) OriginAllowed(r *http.Request) bool {
origin := r.Header.Get("Origin")
if origin == "" {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may or may not want this default.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you let the isOriginAllowed decide?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question :)
Removed.

@rs rs merged commit 64821dd into rs:master Jun 7, 2021
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.

public isOriginAllowed ?
2 participants