Comments (6)
Hey folks, after a few days I came back to take a look on this.
But before I code anything, I think we should first define what is the expected behavior.
At this moment, what the controller is doing is: when receive a request, it checks what Accept
header the client passes and if it's not a whitelisted one (using the ::accept
method on controller definition) it responds with status code 406.
In a certain perspective, this is right. But imo it's not the more semantic way to handle this.
HTTP Accept header is used by the client to inform the server which type of return it accepts. For example, it only accept json and xml as responses, so it inform this to the server and the server should give a response in the correct format to the client.
One other way to handle this would be check the content-type, so the controller would see which content-type the client is using to figure out if it should serve or not a response. This is the way that rails approaches the problem.
What do you think?
@brennovich @joneslee85 @jodosha
from controller.
@carloslopes Hello Carlos, thanks for reporting this 😄
Can you please provide a failing example? For instance, what does your action accepts? What's the HTTP_ACCEPT
header that makes this feature to fail? Thank you. 👍
from controller.
@carloslopes Did you got something to share with us?
from controller.
Hey @jodosha, sorry about the delay, work is really taking all my time!
The feature isn't failing, this is just something that appear when @brennovich and I were take a looking at this issue #118 and we figured out that when we request something passing a Content-Type
header instead of the Accept
one, the controller doesn't filter out that request.
And like a said, I don't know if Accept
is the right header to use for this purpose. If it is, no problem at all, but this is not the convention that other frameworks use (rails and sinatra per example)
from controller.
@carloslopes Thanks for your reply.
Quoting RFC 2616 (HTTP/1.1):
14.1 Accept
The Accept request-header field can be used to specify certain media types which are acceptable for the response.
Accept
is for requests..
14.17 Content-Type
The Content-Type entity-header field indicates the media type of the entity-body sent to the recipient
..while Content-Type
is for responses.
This is the reason why we have named that filter .accept
and why it ignores Content-Type
. 😄
from controller.
Yes, but like it's wrote Accept
is what the client is expecting, it doesn't have anything related to the server behavior (what the server is accepting from the client).
At least this is my understanding, but these RFCs sometimes are totally related to interpretation
from controller.
Related Issues (20)
- Hanami::Action::Flash to use swappable JSON backend HOT 2
- Flash message appears twice (redux) HOT 3
- Exception Handling in Production HOT 19
- RuntimeError: can't add a new key into hash during iteration HOT 8
- Compatability issue with hanami-controller 2.0.0.alpha1 HOT 2
- Is `#request` supposed to be memoized for actions? HOT 2
- Standalone actions prevent using non-keyword parameters in `#initialize` (v2) HOT 3
- [2.0.0.alpha1] Uninitialized constant Hanami::Controller::Configuration (NameError) HOT 2
- Handling `config` and other class-level macros HOT 3
- accept syntax in README no longer seems supported HOT 1
- Action params are not coerced? HOT 5
- Badly encoded cookie strings from Safari results in an error HOT 3
- HTTP status 418 is missing HOT 1
- Issue with multipart/form-data format HOT 1
- Support CSRF by HTTP header HOT 4
- Support for hanami-validations/dry-validations `rule(...)`
- Documentation about Controller/Router integration is incorrect HOT 7
- Fix Response#send_file implementation
- handle_exception should allow exception names as strings
- Where `application/x-www-form-urlencoded` and `multipart/form-data`? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from controller.