Skip to content

refactor(xpp/http): move static response constructors to Response - #84

Merged
mivinci merged 1 commit into
mainfrom
codebuddy/response-static-constructors
Aug 25, 2026
Merged

mivinci merged 1 commit into
mainfrom
codebuddy/response-static-constructors

Conversation

@mivinci

@mivinci mivinci commented Aug 25, 2026

Copy link
Copy Markdown
Owner

Summary

ResponseBuilder::ok/created/no_content/bad_request/not_found/internal_server_error were Response factory constructors in disguise — they build through a throwaway builder, never touching builder state. Response's doc comment already promised this API (Response r = Response::ok("hello");) but the methods lived on the builder.

Moves them to Response (out-of-line definitions, going through Response::builder() exactly as before), leaving ResponseBuilder a pure fluent configurator/terminator. This matches hyper's split: value-type constructors vs Response::builder() for the verbose path.

Also adds Body overloads (Response::ok(Body), etc.) — the terminator already accepts Body, and streaming handlers no longer need the builder chain just to set a 200 status:

// before
return ResponseBuilder().status(StatusCode::Ok).body(Body::from_channel(std::move(rx)));
// after
return Response::ok(Body::from_channel(std::move(rx)));

Changes

  • libxpp/xpp/http/response.h — statics moved (+4 Body overloads), ResponseBuilder back to pure builder
  • libxpp/xpp/http/response_test.cpp, server_test.cpp — 30 mechanical call-site replacements + simplified streaming constructions
  • docs/libxpp/http/{README,body,server}.md — call sites updated, streaming examples simplified

No behavior change.

Validation

  • http_response_test 17/17, http_server_test 13/13
  • Full ASan suite 80/80 (xdns_test network flake passes standalone)
  • mdBook builds clean

ResponseBuilder::ok/created/no_content/bad_request/not_found/
internal_server_error were Response factory constructors in disguise —
they build through a throwaway builder and return a complete Response,
never touching builder state. Response's doc comment already promised
this API ('Response r = Response::ok("hello");') but the methods
lived on the builder.

Move them to Response (defined out-of-line; they go through
Response::builder() exactly as before), leaving ResponseBuilder a pure
fluent configurator/terminator. This matches hyper's split:
value-type constructors vs Response::builder() for the verbose path.

Also adds Response::ok/created/bad_request/internal_server_error(Body)
overloads — the terminator already accepts Body, and the streaming
examples no longer need the builder chain just to set a 200 status
('Response::ok(Body::from_channel(...))').

Call sites updated across tests and the http docs (30 mechanical
replacements + simplified streaming examples). No behavior change.
@mivinci
mivinci merged commit e30ca24 into main Aug 25, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant