mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 10:27:46 +08:00
commands/http: Use constants for header names
This commit is contained in:
parent
1c8d73f9ea
commit
4b9fa9c97c
@ -18,7 +18,10 @@ type Handler struct {
|
||||
|
||||
var ErrNotFound = errors.New("404 page not found")
|
||||
|
||||
const streamHeader = "X-Stream-Output"
|
||||
const (
|
||||
streamHeader = "X-Stream-Output"
|
||||
contentTypeHeader = "Content-Type"
|
||||
)
|
||||
|
||||
var mimeTypes = map[string]string{
|
||||
cmds.JSON: "application/json",
|
||||
@ -63,7 +66,7 @@ func (i Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
mime := mimeTypes[enc]
|
||||
w.Header().Set("Content-Type", mime)
|
||||
w.Header().Set(contentTypeHeader, mime)
|
||||
}
|
||||
|
||||
// if response contains an error, write an HTTP error status code
|
||||
@ -78,7 +81,7 @@ func (i Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
out, err := res.Reader()
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
w.Header().Set(contentTypeHeader, "text/plain")
|
||||
w.Write([]byte(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user