Skip to content

Commit 0f39687

Browse files
committedDec 9, 2015
Merge pull request #2019 from ipfs/Dignifiedquire-fix/access-controll-headers
Dignifiedquire fix/access controll headers
2 parents 243a158 + 74b8a0f commit 0f39687

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed
 

‎commands/http/handler.go

+5
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,11 @@ func sendResponse(w http.ResponseWriter, r *http.Request, res cmds.Response, req
255255
h.Set(contentTypeHeader, mime)
256256
h.Set(transferEncodingHeader, "chunked")
257257

258+
// set 'allowed' headers
259+
h.Set("Access-Control-Allow-Headers", "X-Stream-Output, X-Chunked-Output")
260+
// expose those headers
261+
h.Set("Access-Control-Expose-Headers", "X-Stream-Output, X-Chunked-Output")
262+
258263
if r.Method == "HEAD" { // after all the headers.
259264
return
260265
}

‎commands/http/handler_test.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
coremock "github.com/ipfs/go-ipfs/core/mock"
1212
)
1313

14+
const AllowedExposedHeaders = "X-Stream-Output, X-Chunked-Output"
15+
1416
func assertHeaders(t *testing.T, resHeaders http.Header, reqHeaders map[string]string) {
1517
for name, value := range reqHeaders {
1618
if resHeaders.Get(name) != value {
@@ -170,7 +172,7 @@ func TestAllowedOrigins(t *testing.T) {
170172
ACAMethods: "",
171173
ACACredentials: "",
172174
"Access-Control-Max-Age": "",
173-
"Access-Control-Expose-Headers": "",
175+
"Access-Control-Expose-Headers": AllowedExposedHeaders,
174176
},
175177
Code: http.StatusOK,
176178
}
@@ -198,7 +200,7 @@ func TestWildcardOrigin(t *testing.T) {
198200
ACAMethods: "",
199201
ACACredentials: "",
200202
"Access-Control-Max-Age": "",
201-
"Access-Control-Expose-Headers": "",
203+
"Access-Control-Expose-Headers": AllowedExposedHeaders,
202204
},
203205
Code: http.StatusOK,
204206
}
@@ -258,7 +260,7 @@ func TestAllowedReferer(t *testing.T) {
258260
ACAMethods: "",
259261
ACACredentials: "",
260262
"Access-Control-Max-Age": "",
261-
"Access-Control-Expose-Headers": "",
263+
"Access-Control-Expose-Headers": AllowedExposedHeaders,
262264
},
263265
Code: http.StatusOK,
264266
}
@@ -286,7 +288,7 @@ func TestWildcardReferer(t *testing.T) {
286288
ACAMethods: "",
287289
ACACredentials: "",
288290
"Access-Control-Max-Age": "",
289-
"Access-Control-Expose-Headers": "",
291+
"Access-Control-Expose-Headers": AllowedExposedHeaders,
290292
},
291293
Code: http.StatusOK,
292294
}

‎core/corehttp/gateway_handler.go

+5
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
134134
i.addUserHeaders(w) // ok, _now_ write user's headers.
135135
w.Header().Set("X-IPFS-Path", urlPath)
136136

137+
// set 'allowed' headers
138+
w.Header().Set("Access-Control-Allow-Headers", "X-Stream-Output, X-Chunked-Output")
139+
// expose those headers
140+
w.Header().Set("Access-Control-Expose-Headers", "X-Stream-Output, X-Chunked-Output")
141+
137142
// Suborigin header, sandboxes apps from each other in the browser (even
138143
// though they are served from the same gateway domain).
139144
//

‎test/sharness/t0230-channel-streaming-http-content-type.sh

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ test_ls_cmd() {
2121

2222
test_expect_success "Text encoded channel-streaming command output looks good" '
2323
printf "HTTP/1.1 200 OK\r\n" >expected_output &&
24+
printf "Access-Control-Allow-Headers: X-Stream-Output, X-Chunked-Output\r\n" >>expected_output &&
25+
printf "Access-Control-Expose-Headers: X-Stream-Output, X-Chunked-Output\r\n" >>expected_output &&
2426
printf "Content-Type: text/plain\r\n" >>expected_output &&
2527
printf "Trailer: X-Stream-Error\r\n" >>expected_output &&
2628
printf "Transfer-Encoding: chunked\r\n" >>expected_output &&
@@ -41,6 +43,8 @@ test_ls_cmd() {
4143

4244
test_expect_success "JSON encoded channel-streaming command output looks good" '
4345
printf "HTTP/1.1 200 OK\r\n" >expected_output &&
46+
printf "Access-Control-Allow-Headers: X-Stream-Output, X-Chunked-Output\r\n" >>expected_output &&
47+
printf "Access-Control-Expose-Headers: X-Stream-Output, X-Chunked-Output\r\n" >>expected_output &&
4448
printf "Content-Type: application/json\r\n" >>expected_output &&
4549
printf "Trailer: X-Stream-Error\r\n" >>expected_output &&
4650
printf "Transfer-Encoding: chunked\r\n" >>expected_output &&

0 commit comments

Comments
 (0)
Please sign in to comment.