Fast path for setting headers.

- No heap allocation
- No indirection
- CanonicalMIMEHeaderKey() is not called
This commit is contained in:
Manu Mtz-Almeida
2015-05-23 16:39:25 +02:00
parent 35fd7fb480
commit a2105ce34c
4 changed files with 9 additions and 9 deletions
+3 -3
View File
@@ -19,15 +19,15 @@ type (
}
)
const jsonContentType = "application/json; charset=utf-8"
var jsonContentType = []string{"application/json; charset=utf-8"}
func (r JSON) Write(w http.ResponseWriter) error {
w.Header().Set("Content-Type", jsonContentType)
w.Header()["Content-Type"] = jsonContentType
return json.NewEncoder(w).Encode(r.Data)
}
func (r IndentedJSON) Write(w http.ResponseWriter) error {
w.Header().Set("Content-Type", jsonContentType)
w.Header()["Content-Type"] = jsonContentType
jsonBytes, err := json.MarshalIndent(r.Data, "", " ")
if err != nil {
return err