request is nil in middleware on missing or incorrect content_type
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 10k
- Forks
- 1.2k
- Avg merge
- 14h 38m
- Merged PRs (30d)
- 92
Description
We have a Logger that extends from the Grape middleman base. This logger need to have access to the request from env["api.request"] in the after method, which when a http request is sent with no content_type defined env["api.request"].request is nil which raises an error.
We are currently mounted with the use method
The following is the middle man call trace. Our middleware is API::Logger.
# Middleware call trace
## GOOD, correct content_type
### Before
API::Logger
Grape::Middleware::Versioner::Path
Grape::Middleware::Formatter
- Calls app endpoint here, logs sql whatnot
### After
Grape::Middleware::Formatter
Grape::Middleware::Versioner::Path
API::Logger
## BAD, missing content_type
### Before
API::Logger
Grape::Middleware::Versioner::Path
Grape::Middleware::Formatter
- Does NOT hit api
### After
Grape::Middleware::Versioner::Path
API::Logger
- raises error because request is missing from env["api.endpoint"]
One weird part in the bad calls is it goes up.
API::Logger
Grape::Middleware::Versioner::Path
Grape::Middleware::Formatter
but then one way down.
Grape::Middleware::Versioner::Path
API::Logger
My question is the request deleted if it does not match the content_type required or is this a bug?
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
No source files or tests are named. Start by reproducing a request with missing or incorrect content_type and trace Grape::Middleware::Formatter, Grape::Middleware::Versioner::Path, and API::Logger around env["api.request"]. Establish the expected middleware and request behavior, then verify it with regression coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100