Skip to content

Commit

Permalink
Add Server field in HTTP API
Browse files Browse the repository at this point in the history
Resolves #625
Included in tests.

License: MIT
Signed-off-by: Jakub (Kubuxu) Sztandera <kubuxu@gmail.com>
  • Loading branch information
Kubuxu committed Jan 5, 2016
1 parent 65785e0 commit 8035a3a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions commands/http/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ func guessMimeType(res cmds.Response) (string, error) {
}

func sendResponse(w http.ResponseWriter, r *http.Request, res cmds.Response, req cmds.Request) {
h := w.Header()
// Expose our agent to allow identification
h.Set("Server", "go-ipfs/" + config.CurrentVersionNumber)

mime, err := guessMimeType(res)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
Expand All @@ -222,8 +226,6 @@ func sendResponse(w http.ResponseWriter, r *http.Request, res cmds.Response, req
return
}

h := w.Header()

// Set up our potential trailer
h.Set("Trailer", StreamErrHeader)

Expand Down Expand Up @@ -261,7 +263,7 @@ func sendResponse(w http.ResponseWriter, r *http.Request, res cmds.Response, req
h.Set("Access-Control-Allow-Headers", "X-Stream-Output, X-Chunked-Output")
// expose those headers
h.Set("Access-Control-Expose-Headers", "X-Stream-Output, X-Chunked-Output")

if r.Method == "HEAD" { // after all the headers.
return
}
Expand Down
2 changes: 2 additions & 0 deletions test/sharness/t0230-channel-streaming-http-content-type.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ test_ls_cmd() {

test_expect_success "Text encoded channel-streaming command output looks good" '
printf "HTTP/1.1 200 OK\r\n" >expected_output &&
printf "Server: go-ipfs/%s\r\n" $(ipfs version -n) >>expected_output &&
printf "Access-Control-Allow-Headers: X-Stream-Output, X-Chunked-Output\r\n" >>expected_output &&
printf "Access-Control-Expose-Headers: X-Stream-Output, X-Chunked-Output\r\n" >>expected_output &&
printf "Content-Type: text/plain\r\n" >>expected_output &&
Expand All @@ -43,6 +44,7 @@ test_ls_cmd() {

test_expect_success "JSON encoded channel-streaming command output looks good" '
printf "HTTP/1.1 200 OK\r\n" >expected_output &&
printf "Server: go-ipfs/%s\r\n" $(ipfs version -n) >>expected_output &&
printf "Access-Control-Allow-Headers: X-Stream-Output, X-Chunked-Output\r\n" >>expected_output &&
printf "Access-Control-Expose-Headers: X-Stream-Output, X-Chunked-Output\r\n" >>expected_output &&
printf "Content-Type: application/json\r\n" >>expected_output &&
Expand Down

0 comments on commit 8035a3a

Please sign in to comment.