mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-30 09:59:13 +08:00
address CR comment re interface in cmds http handler
https://github.com/ipfs/go-ipfs/pull/1529#discussion_r35662230 License: MIT Signed-off-by: Juan Batiz-Benet <juan@benet.ai>
This commit is contained in:
@ -70,13 +70,15 @@ type ServerConfig struct {
|
|||||||
|
|
||||||
func skipAPIHeader(h string) bool {
|
func skipAPIHeader(h string) bool {
|
||||||
switch h {
|
switch h {
|
||||||
|
case "Access-Control-Allow-Origin":
|
||||||
|
return true
|
||||||
|
case "Access-Control-Allow-Methods":
|
||||||
|
return true
|
||||||
|
case "Access-Control-Allow-Credentials":
|
||||||
|
return true
|
||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
case "Access-Control-Allow-Origin":
|
|
||||||
case "Access-Control-Allow-Methods":
|
|
||||||
case "Access-Control-Allow-Credentials":
|
|
||||||
}
|
}
|
||||||
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) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 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) {
|
|||||||
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)
|
||||||
|
Reference in New Issue
Block a user