Skip to content

Commit

Permalink
Support negative Content-Length in DataFromReader
Browse files Browse the repository at this point in the history
You can get an http.Response with ContentLength set to -1 (Chunked encoding), so
for DataFromReader to be useful for those we need to support that.
  • Loading branch information
segevfiner authored Jul 8, 2019
1 parent e602d52 commit cd328bb
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion render/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ type Reader struct {
// Render (Reader) writes data with custom ContentType and headers.
func (r Reader) Render(w http.ResponseWriter) (err error) {
r.WriteContentType(w)
r.Headers["Content-Length"] = strconv.FormatInt(r.ContentLength, 10)
if r.ContentLength >= 0 {
r.Headers["Content-Length"] = strconv.FormatInt(r.ContentLength, 10)
}
r.writeHeaders(w, r.Headers)
_, err = io.Copy(w, r.Reader)
return
Expand Down

0 comments on commit cd328bb

Please sign in to comment.