From 68d6af1e82c9132f62577ef0a0a63a7c6342f93d Mon Sep 17 00:00:00 2001 From: Robert Obryk Date: Fri, 8 Nov 2013 01:53:08 +0100 Subject: [PATCH] httputil: set the headers before writing them Change-Id: Ibb7db1ca06744b64ec29664059364fe7a1e8e837 --- pkg/httputil/httputil.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/httputil/httputil.go b/pkg/httputil/httputil.go index 6fb067b8f..df1c6baaf 100644 --- a/pkg/httputil/httputil.go +++ b/pkg/httputil/httputil.go @@ -75,13 +75,13 @@ func ReturnJSON(rw http.ResponseWriter, data interface{}) { func ReturnJSONCode(rw http.ResponseWriter, code int, data interface{}) { rw.Header().Set("Content-Type", "text/javascript") - rw.WriteHeader(code) js, err := json.MarshalIndent(data, "", " ") if err != nil { BadRequestError(rw, fmt.Sprintf("JSON serialization error: %v", err)) return } rw.Header().Set("Content-Length", strconv.Itoa(len(js)+1)) + rw.WriteHeader(code) rw.Write(js) rw.Write([]byte("\n")) }