Created
September 11, 2022 06:10
-
-
Save percybolmer/8e5622f896fce9047196d92348aa5fb8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ( | |
/** | |
websocketUpgrader is used to upgrade incomming HTTP requests into a persitent websocket connection | |
*/ | |
websocketUpgrader = websocket.Upgrader{ | |
// Apply the Origin Checker | |
CheckOrigin: checkOrigin, | |
ReadBufferSize: 1024, | |
WriteBufferSize: 1024, | |
} | |
) | |
var ( | |
ErrEventNotSupported = errors.New("this event type is not supported") | |
) | |
// checkOrigin will check origin and return true if its allowed | |
func checkOrigin(r *http.Request) bool { | |
// Grab the request origin | |
origin := r.Header.Get("Origin") | |
switch origin { | |
case "http://localhost:8080": | |
return true | |
default: | |
return false | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment