Skip to content

Commit

Permalink
address CR comment re interface in cmds http handler
Browse files Browse the repository at this point in the history
ipfs#1529 (comment)

License: MIT
Signed-off-by: Juan Batiz-Benet <[email protected]>
  • Loading branch information
jbenet authored and kbala444 committed Aug 15, 2015
1 parent 40abf91 commit 4357eec
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions commands/http/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,15 @@ type ServerConfig struct {

func skipAPIHeader(h string) bool {
switch h {
default:
return false
case "Access-Control-Allow-Origin":
return true
case "Access-Control-Allow-Methods":
return true
case "Access-Control-Allow-Credentials":
return true
default:
return false
}
return true
}

func NewHandler(ctx cmds.Context, root *cmds.Command, cfg *ServerConfig) *Handler {
Expand Down Expand Up @@ -151,7 +153,7 @@ func (i internalHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}

// now handle responding to the client properly
sendResponse(w, r, req, res)
sendResponse(w, r, res, req)
}

func guessMimeType(res cmds.Response) (string, error) {
Expand All @@ -167,7 +169,7 @@ func guessMimeType(res cmds.Response) (string, error) {
return mimeTypes[enc], nil
}

func sendResponse(w http.ResponseWriter, r *http.Request, req cmds.Request, res cmds.Response) {
func sendResponse(w http.ResponseWriter, r *http.Request, res cmds.Response, req cmds.Request) {
mime, err := guessMimeType(res)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
Expand Down

0 comments on commit 4357eec

Please sign in to comment.