Skip to content

response.set_body() no longer exists #281

Open

Description

@R-Goc

In a large number of places in the documentation response.set_body() is used. Mainly in the router. For example:

router<route_params> r;
r.get( "/hello",
    []( route_params& p )
    {
        p.res.status( status::ok );
        p.res.set_body( "Hello, world!" );
        return route_done;
    } );

This method no longer exists.

Activity

  1. vinniefalco commented on Aug 13, 2026

    @vinniefalco
    Member
  2. ashtum commented on Aug 13, 2026

    @ashtum
    Collaborator

    This is after refactoring the router to use coroutines. The new way of doing it is:

    auto [ec] = co_await rp.send(body);

    You can also use rp.res_body to stream the body incrementally (that’s what’s happening in static_server.cpp).

    The docs need updating. I’ll work on them after I’m done with the Burl serializer (next week).

  3. R-Goc commented on Aug 13, 2026

    @R-Goc
    Author

    How does this interact with using the serializer? If not using the serializer it will be an addional memcpy for the body compared to using a sink with prepare() right?

  4. ashtum commented on Aug 13, 2026

    @ashtum
    Collaborator

    How does this interact with using the serializer? If not using the serializer it will be an addional memcpy for the body compared to using a sink with prepare() right?

    Yes, it currently makes a copy, but this is exactly what I'm currently working on in the boost.burl project (the work there will eventually be merged into this project). While the interface will remain pretty much the same, it won't make a copy.

    This is already resolved on the parser side, although the changes haven't been merged into this project yet.

  5. R-Goc commented on Aug 13, 2026

    @R-Goc
    Author

    The body I pass to rp.send must already be serialised right?

  6. ashtum commented on Aug 13, 2026

    @ashtum
    Collaborator

    The body I pass to rp.send must already be serialised right?

    Yes, the string_view passed to send will be used as the body of the response, with Content-Length set to the same size as the string_view.

    Structural types, like Boost.JSON types, can benefit from the streaming interface. So, in the future, you could do:

    auto [ec] = co_await rp.send(json);

    And it will serialize the json value in-place (using the serialzier's internal buffer).

  7. R-Goc commented on Aug 14, 2026

    @R-Goc
    Author

    The doc for res_body needs to be changed. I thought you could attach it if you wanted a body, but you actually have to set it to a sink from your socket otherwise you get a null pointer dereference in send.

    /// Provides access to the response body
        http::any_buffer_sink res_body;
    

    Ideally this would be a compile time failure too, or some error, not an exception directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    • Status
      Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions