Support aborting requests via a Rack::Response#finish
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 10k
- Forks
- 1.2k
- Avg merge
- 14h 38m
- Merged PRs (30d)
- 92
Description
I have a post endpoint where I'd like to conditionally return a custom Rack::Response, like so:
post do
if some_condition?
hash_of_contextually_relevant_goodness = { foo: 'bar' }
Rack::Response.new(
[hash_of_contextually_relevant_goodness],
418,
{ 'Content-Type' => 'application/json' }
).finish
else
# do some object creation stuff
end
end
However, this returns the following response body:
[
418,
{
"Content-Length": "13",
"Content-Type": "application/json"
},
{
"block": {},
"body": {
"block": null,
"body": [
"{:foo=>\"bar\"}"
],
"chunked": false,
"header": {
"Content-Length": "13",
"Content-Type": "application/json"
},
"length": 13,
"status": 418,
"writer": {}
},
"closed": false
}
]
It looks like the response is doubling up. What is the correct way to return a custom Rack::Response from my endpoint?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing how the endpoint handles the returned Rack::Response and how Rack::Response#finish is interpreted. Reproduce the post endpoint example, then inspect the request/response handling path for where the response becomes nested. Done means a custom Rack::Response can be returned without its status, headers, and body being serialized again.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100