@cryptotaxi247 / kubo / commits / 4b9fa9c97

commands/http: Use constants for header names

Matt Bell committed Nov 16, 2014 at 00:45 UTC 4b9fa9c97c86c30f4aa6cc84af778a10c1a6fdd7
1 file changed +6 -3
commands/http/handler.go
+6 -3
@@ -18,7 +18,10 @@ type Handler struct {
18
19 var ErrNotFound = errors.New("404 page not found")
20
21 -const streamHeader = "X-Stream-Output"
21 +const (
22 + streamHeader = "X-Stream-Output"
23 + contentTypeHeader = "Content-Type"
24 +)
25
26 var mimeTypes = map[string]string{
27 cmds.JSON: "application/json",
@@ -63,7 +66,7 @@ func (i Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
66 return
67 }
68 mime := mimeTypes[enc]
66 - w.Header().Set("Content-Type", mime)
69 + w.Header().Set(contentTypeHeader, mime)
70 }
71
72 // 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) {
81 out, err := res.Reader()
82 if err != nil {
83 w.WriteHeader(http.StatusInternalServerError)
81 - w.Header().Set("Content-Type", "text/plain")
84 + w.Header().Set(contentTypeHeader, "text/plain")
85 w.Write([]byte(err.Error()))
86 return
87 }