Commit 0cd37df2 authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

address CR comment re interface in cmds http handler

https://github.com/ipfs/go-ipfs/pull/1529#discussion_r35662230

License: MIT
Signed-off-by: default avatarJuan Batiz-Benet <juan@benet.ai>
parent 135e1fc4
...@@ -70,13 +70,15 @@ type ServerConfig struct { ...@@ -70,13 +70,15 @@ type ServerConfig struct {
func skipAPIHeader(h string) bool { func skipAPIHeader(h string) bool {
switch h { switch h {
default:
return false
case "Access-Control-Allow-Origin": case "Access-Control-Allow-Origin":
return true
case "Access-Control-Allow-Methods": case "Access-Control-Allow-Methods":
return true
case "Access-Control-Allow-Credentials": case "Access-Control-Allow-Credentials":
return true
default:
return false
} }
return true
} }
func NewHandler(ctx cmds.Context, root *cmds.Command, cfg *ServerConfig) *Handler { func NewHandler(ctx cmds.Context, root *cmds.Command, cfg *ServerConfig) *Handler {
...@@ -151,7 +153,7 @@ func (i internalHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { ...@@ -151,7 +153,7 @@ func (i internalHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
// now handle responding to the client properly // now handle responding to the client properly
sendResponse(w, r, req, res) sendResponse(w, r, res, req)
} }
func guessMimeType(res cmds.Response) (string, error) { func guessMimeType(res cmds.Response) (string, error) {
...@@ -167,7 +169,7 @@ func guessMimeType(res cmds.Response) (string, error) { ...@@ -167,7 +169,7 @@ func guessMimeType(res cmds.Response) (string, error) {
return mimeTypes[enc], nil 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) mime, err := guessMimeType(res)
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment