Repository navigation
refactor(xpp/http): move static response constructors to Response - #84
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ResponseBuilder::ok/created/no_content/bad_request/not_found/internal_server_errorwere 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 throughResponse::builder()exactly as before), leavingResponseBuildera pure fluent configurator/terminator. This matches hyper's split: value-type constructors vsResponse::builder()for the verbose path.Also adds
Bodyoverloads (Response::ok(Body), etc.) — the terminator already acceptsBody, and streaming handlers no longer need the builder chain just to set a 200 status:Changes
libxpp/xpp/http/response.h— statics moved (+4Bodyoverloads), ResponseBuilder back to pure builderlibxpp/xpp/http/response_test.cpp,server_test.cpp— 30 mechanical call-site replacements + simplified streaming constructionsdocs/libxpp/http/{README,body,server}.md— call sites updated, streaming examples simplifiedNo behavior change.
Validation