Skip to content

Commit

Permalink
add OPTIONS support for /ui/keywords (#4992)
Browse files Browse the repository at this point in the history
Fixes #4946.
  • Loading branch information
abhimanyusinghgaur authored and danielmai committed Apr 24, 2020
1 parent 19a1ad8 commit a8e80f8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion dgraph/cmd/alpha/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ func homeHandler(w http.ResponseWriter, r *http.Request) {
// Used to return a list of keywords, so that UI can show them for autocompletion.
func keywordHandler(w http.ResponseWriter, r *http.Request) {
x.AddCorsHeaders(w)
if r.Method != "GET" {
if r.Method == http.MethodOptions {
return
}

if r.Method != http.MethodGet {
http.Error(w, x.ErrorInvalidMethod, http.StatusBadRequest)
return
}
Expand Down
11 changes: 11 additions & 0 deletions dgraph/cmd/alpha/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -806,3 +806,14 @@ func TestDrainingMode(t *testing.T) {
setDrainingMode(t, false)
runRequests(false)
}

func TestOptionsForUiKeywords(t *testing.T) {
req, err := http.NewRequest(http.MethodOptions, fmt.Sprintf("%s/ui/keywords", addr), nil)
require.NoError(t, err)

client := &http.Client{}

resp, err := client.Do(req)
require.NoError(t, err)
require.True(t, resp.StatusCode >= 200 && resp.StatusCode < 300)
}

0 comments on commit a8e80f8

Please sign in to comment.