Browse Source

expose Content-Type to CORS

deiu 5 years ago
parent
commit
1769db4677
2 changed files with 4 additions and 1 deletions
  1. 3 0
      proxy_test.go
  2. 1 1
      server.go

+ 3 - 0
proxy_test.go

@@ -3,6 +3,7 @@ package gold
 import (
 	"io/ioutil"
 	"net/http"
+	"strings"
 	"testing"
 
 	"github.com/stretchr/testify/assert"
@@ -27,8 +28,10 @@ func TestProxyQueryOPTION(t *testing.T) {
 	request, err := http.NewRequest("OPTIONS", testServer.URL+"/"+QueryPath, nil)
 	assert.NoError(t, err)
 	request.Header.Add("Origin", "example.org")
+	request.Header.Add("Content-Type", "test/tql")
 	response, err := httpClient.Do(request)
 	assert.NoError(t, err)
 	assert.Equal(t, 200, response.StatusCode)
 	assert.Equal(t, "example.org", response.Header.Get("Access-Control-Allow-Origin"))
+	assert.True(t, strings.Contains(response.Header.Get("Access-Control-Expose-Headers"), "Content-Type"))
 }

+ 1 - 1
server.go

@@ -246,7 +246,7 @@ func (s *Server) handle(w http.ResponseWriter, req *httpRequest) (r *response) {
 
 	// CORS
 	w.Header().Set("Access-Control-Allow-Credentials", "true")
-	w.Header().Set("Access-Control-Expose-Headers", "User, Location, Link, Vary, Last-Modified, WWW-Authenticate, Content-Length, Accept-Patch, Accept-Post, Allow, Updates-Via, Ms-Author-Via")
+	w.Header().Set("Access-Control-Expose-Headers", "User, Location, Link, Vary, Last-Modified, WWW-Authenticate, Content-Length, Content-Type, Accept-Patch, Accept-Post, Allow, Updates-Via, Ms-Author-Via")
 	w.Header().Set("Access-Control-Max-Age", "1728000")
 
 	// RWW