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

Is it possible to return a Dancer::Response that is left unchanged? #1211

Open
nicolasfranck opened this issue Mar 16, 2020 · 4 comments
Open

Comments

@nicolasfranck
Copy link

I'm trying to make Dancer accept my response, and leave it unchanged.
I've used send_file, and also Dancer::Response, but when the
response has text like content, it tries to reencode it, and adds charset
to the header content-type. Returning a Dancer::Response with the flag
"encoded" on, fixes the problem with reencoding, but still adds the charset.

Any idea?

@bigpresh
Copy link
Member

Does it work if you set the desired charset yourself?

RFC 7231 says:

A sender that generates a message containing a payload body SHOULD generate a Content-Type header field in that message unless the intended media type of the enclosed representation is unknown to the sender

So, while that's a SHOULD not a MUST, it's still recommended practice to have a correct charset.

@nicolasfranck
Copy link
Author

Well, I kind of agree. Sigh, I'm trying to implement JSON API v1 (https://jsonapi.org/format/#content-negotiation-servers), and they require the Content-Type to be only "application/vnd.api+json" without any additional parameters. Their answer
to "charset" is that JSON is required to be utf-8 (well, that to the browsers).

Be that as it may, why not simply trust a Dancer::Response?
It's up to the implementer to make a decent response.

@bigpresh
Copy link
Member

I think setting a default value if the user didn't specify one themselves is more correct in the majority of cases, for DWIMmery and concise code, and is going to be helpful far more often than it would be a hinderance.

I'm torn here; if you return a Dancer::Response object yourself, it's fairly clear that you know what you're doing and you wish to override a lot of Dancer's helpfulness and just say "here, just use this response". On the other hand, it's a change which could surprise anyone who was returning a response object for any reason but expecting the previous behaviour.

I shall have a think :)

@nicolasfranck
Copy link
Author

nicolasfranck commented Mar 16, 2020

well, returning a Dancer::Response is not documented for the moment, so I do not think that anyone is expecting anything. Does send_file return a Dancer::Response? That would complicate things..

You can always add a flag raw to the response object and take that into account, which is new behaviour.

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

No branches or pull requests

2 participants