Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request is nil in middleware on missing or incorrect content_type #1792

Open
ChrisCPO opened this issue Sep 19, 2018 · 4 comments
Open

request is nil in middleware on missing or incorrect content_type #1792

ChrisCPO opened this issue Sep 19, 2018 · 4 comments
Labels

Comments

@ChrisCPO
Copy link

ChrisCPO commented Sep 19, 2018

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?

@ChrisCPO
Copy link
Author

possibly related to #1587

@dblock dblock added the bug? label Sep 20, 2018
@dblock
Copy link
Member

dblock commented Sep 20, 2018

I would say seems like a bug, and I would fix #1587 first because that one is a bit clearer

That said, try writing a spec for this? It will narrow down what's going on.

@ChrisCPO
Copy link
Author

@dblock I have a failing spec for this. I will extract it out into new rails app.

@dblock
Copy link
Member

dblock commented Sep 21, 2018

PR the spec instead here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants