fix: error-raising handlers and HttpResponse::body Content-Type inference - #26
Merged
Conversation
HttpResponse::body previously serialized only the responder output, so
custom-status responses like HttpResponse::new(BadRequest).body("...")
kept their status and body but emitted no Content-Type header.
Probe the body responder's options and carry only its default
Content-Type into the response when no explicit Content-Type was set.
Explicit headers still take precedence, the response status is
preserved, and no other responder effects (headers, cookies, status)
are merged. HttpResponse::json inherits the same rule via body().
Add black-box tests covering direct String/Json/Html responders,
custom-status body values, HttpResponse::json, and explicit
Content-Type overrides.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
Two fixes on this branch:
1. Allow request handlers to raise errors (existing commit)
HttpHandler/Middleware/dispatch_httpno longer requirenoraise, so handlers and middleware may raise checked errors.Mocket::on_error.2. Infer body responder Content-Type in
HttpResponse::body/jsonHttpResponse::bodypreviously serialized only the responder output, so custom-status responses kept their status and body but emitted no Content-Type at all:Contract (documented in doc comments): the body responder's default
Content-Typeis carried into the response only when no explicitContent-Typewas set. Explicit headers take precedence, the response status is preserved, and no other responder effects (arbitrary headers, cookies, status) are merged. Implemented by probing the responder'soptionsagainst a throwaway response and extracting onlyContent-Type— no public API change.Tests
responder_test.mbt: direct String/Json/Html responders, custom-statusbodyvalues,HttpResponse::json, and explicitContent-Typeoverrides.error_wbtest.mbtcovers error-to-response conversion andon_error.moon test→ 59 passed;moon check→ clean.🤖 Generated with Claude Code