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