Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added allow-methods header to options
  • Loading branch information
Levi Lovelock committed Aug 28, 2015
1 parent 79f829a commit 1a4ff29
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions conn/options.go
Expand Up @@ -2,6 +2,11 @@ package conn

import "net/http"

const (
ALLOWED_METHODS = "GET, POST, OPTIONS"
)

func optionsHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Access-Control-Allow-Methods", ALLOWED_METHODS)
w.WriteHeader(200)
}
9 changes: 9 additions & 0 deletions conn/options_test.go
Expand Up @@ -31,3 +31,12 @@ func TestOptionsEndpointReturnsNoBody(t *testing.T) {

assert.Equal(t, "", recorder.Body.String())
}

func TestOptionsEndpointReturnsMethods(t *testing.T) {
recorder := httptest.NewRecorder()
req, _ := http.NewRequest("OPTIONS", connUrl, nil)

handler.ServeHTTP(recorder, req)

assert.Equal(t, "GET, POST, OPTIONS", recorder.Header().Get("Access-Control-Allow-Methods"))
}

0 comments on commit 1a4ff29

Please sign in to comment.