Skip to content

HTTP2 outgoing messages should set content-length if payload knows it #1547

Closed
@seanmonstar

Description

@seanmonstar

For instance, a server replying with Response::new(Body::from("Hello, World!")) over HTTP2 should set the content-length: 13 header.

Steps to fix

  • In proto::h2::server, before calling SendResponse::send_response, check body.content_length(). If it returns Some(len), check if the headers contain CONTENT_LENGTH, and if not, add the header with the serialized length.
  • Do the same in proto::h2::client, before calling SendRequest::send_request.
  • Serializing into a header value can make use of hyper::headers::content_length_value.
  • A new function, set_content_length_if_not_present, could probably be added to hyper::headers, making use of HeaderMap::entry.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-http2Area: HTTP/2 specific.C-featureCategory: feature. This is adding a new feature.E-easyEffort: easy. A task that would be a great starting point for a new contributor.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions