Skip to content

HTTP/HTTPS client has no response-body framing (chunked / Content-Length / close-terminated) #33

Description

@binaryduke

The HTTP and HTTPS clients have no way to read a response body correctly, because there is no RFC-7230 message-framing logic anywhere in the library. Grepping the tree for Transfer-Encoding, chunked, Content-Length or any body-reading helper returns nothing (checked in V1.4.0 and current main / V1.5.0).

Symptom

Issuing a GET against any real-world server and trying to read the body via stream::await / resolve / pipe gives a truncated body, a hang, or the raw chunked framing bytes mixed into the payload — depending on how the server chose to frame the response. There is no correct way to consume the body today.

Why it can't be worked around cleanly at the call site

The caller cannot know which of the three framings the server used without parsing the headers and then applying the matching read strategy — which is precisely the logic that belongs in the client.

What's needed

A read_body() on the http/https client implementing the standard three cases:

  1. Transfer-Encoding: chunked → read and de-chunk until the terminating zero-length chunk
  2. Content-Length: N → read exactly N bytes
  3. neither → read until the server closes the connection (close-terminated)

We have implemented exactly this as an additive http::read_body() / https::read_body() (~186 lines, no change to stream::await / resolve / pipe, so nothing existing breaks). Happy to open a PR if you want it.

Related, and arguably a regression

V1.5.0 appears to have removed the request-side Content-Length write that V1.4.0 had. If so, an outgoing POST body is now itself unframeable — the same class of bug in the other direction. Worth a look.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions