Skip to content
Snippets Groups Projects
Commit d72e11d0 authored by Will McCutchen's avatar Will McCutchen
Browse files

Always set Content-Length for normal responses

parent aabe5a1f
No related branches found
No related tags found
No related merge requests found
......@@ -87,7 +87,6 @@ func (h *HTTPBin) Gzip(w http.ResponseWriter, r *http.Request) {
gzBody := buf.Bytes()
w.Header().Set("Content-Encoding", "gzip")
w.Header().Set("Content-Length", fmt.Sprintf("%d", len(gzBody)))
writeJSON(w, gzBody, http.StatusOK)
}
......@@ -108,7 +107,6 @@ func (h *HTTPBin) Deflate(w http.ResponseWriter, r *http.Request) {
compressedBody := buf.Bytes()
w.Header().Set("Content-Encoding", "deflate")
w.Header().Set("Content-Length", fmt.Sprintf("%d", len(compressedBody)))
writeJSON(w, compressedBody, http.StatusOK)
}
......
......@@ -2,6 +2,7 @@ package httpbin
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"net/url"
......@@ -48,6 +49,7 @@ func getURL(r *http.Request) *url.URL {
func writeJSON(w http.ResponseWriter, body []byte, status int) {
w.Header().Set("Content-Type", jsonContentType)
w.Header().Set("Content-Length", fmt.Sprintf("%d", len(body)))
w.WriteHeader(status)
w.Write(body)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment