Skip to content

Commit

Permalink
added http(s) support for origin
Browse files Browse the repository at this point in the history
  • Loading branch information
igm committed May 14, 2014
1 parent 41cec30 commit 6ed5e37
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion sockjs/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
)

func (h *handler) sockjsWebsocket(rw http.ResponseWriter, req *http.Request) {
if req.Header.Get("Origin") != "http://"+req.Host {
origin := req.Header.Get("Origin")
if origin != "http://"+req.Host && origin != "https://"+req.Host {
http.Error(rw, "Origin not allowed", 403)
return
}
Expand Down
2 changes: 1 addition & 1 deletion sockjs/websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestHandler_WebSocketHandshakeError(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(h.sockjsWebsocket))
defer server.Close()
req, _ := http.NewRequest("GET", server.URL, nil)
req.Header.Set("origin", server.URL)
req.Header.Set("origin", "https"+server.URL[4:])
resp, _ := http.DefaultClient.Do(req)
if resp.StatusCode != http.StatusBadRequest {
t.Errorf("Unexpected response code, got '%d', expected '%d'", resp.StatusCode, http.StatusBadRequest)
Expand Down

0 comments on commit 6ed5e37

Please sign in to comment.