httpx.Response: Add 'Content-Length' header

This commit is contained in:
Tom Wiesing 2022-12-30 20:18:27 +01:00
parent 1caecc0f19
commit 2d5b92f464
No known key found for this signature in database

View file

@ -2,6 +2,7 @@ package httpx
import ( import (
"net/http" "net/http"
"strconv"
) )
// Response represents a response to an http request. // Response represents a response to an http request.
@ -16,6 +17,7 @@ func (response Response) ServeHTTP(w http.ResponseWriter, r *http.Request) {
response.ContentType = "text/plain" response.ContentType = "text/plain"
} }
w.Header().Set("Content-Type", response.ContentType) w.Header().Set("Content-Type", response.ContentType)
w.Header().Set("Content-Length", strconv.Itoa(len(response.Body)))
if response.StatusCode <= 0 { if response.StatusCode <= 0 {
response.StatusCode = http.StatusOK response.StatusCode = http.StatusOK