Skip to content

Failure dump truncates or destroys the response body (Content-Length is not updated) #18

Description

@korya

Problem

httpResponse.writeTo replaces res.Body with a rendered representation (hex dump, cropped text, or a placeholder) but never updates res.ContentLength. It then calls res.Write(w), which is an HTTP wire-format serializer and copies exactly ContentLength bytes. Any rendered form longer than the original body gets cut off.

Reproduction

a) --silent mode — placeholder truncated to 4 characters (body is boom, Content-Length: 4):

$ http-assert -s --assert-ok http://127.0.0.1:8791/500

HTTP/1.1 500 Internal Server Error
Content-Length: 4

  <<          ← expected "  << Payload is omitted >>"

b) Binary body (8 bytes) — hex dump reduced to a single field:

$ http-assert -v --assert-body-eq 'x' http://127.0.0.1:8791/binary

Content-Length: 8

00000000    ← the entire hex dump

c) gzip'd body (40 bytes) — hex dump cut mid-line:

HTTP/1.1 200 OK
Content-Length: 40
Content-Encoding: gzip

00000000  1f 8b 08 00 00 00 00 00  02 ff

Why it matters

--silent is the mode the README's own monitoring script recommends, so the mode most likely to be deployed is the mode that hides the diagnostic. For binary and compressed responses the hex dumper — whose entire purpose is showing you the bytes — shows nothing usable.

Root cause

Rendering and transport framing are conflated: http.Response.Write is reused as a pretty-printer. The short-write error is discarded (_ = r.Write(w)), which is why this went unnoticed.

Affected code

main.gohttpResponse.writeTo

Suggested fix

Don't use http.Response.Write for human-readable output. Either format the status line + headers + rendered body manually, or set r.ContentLength = int64(len(rendered)) (and clear Transfer-Encoding) before writing. Stop discarding the write error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions