-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
JSON served as HTML content_type since v2.1 #1647
Comments
How are you setting the content type to |
@jkowens with content_type :json But I realized it works for a direct request. But it clearly changed since I've updated to Sinatra 2.1 . |
Yes, there was a change to add a |
Yeah so basically my code is using So far it was working fine with the content type set to
And here are the response headers:
If I type the URI in the address bar instead, then Sinatra sets it to "application/json" or the vnd version in Firefox. Not sure it has any influence but the URI does not have ".json" at the end. In the meantime as a quick fix I check if the returned data is a string and if the first characters is "{". |
Do you set |
In a before filter. |
I'm trying to reproduce the issue, but it seems to be working as expected for me. Here is my test app:
Response Headers: HTTP/1.1 200 OK |
@mig-hub if you can provide a small sample app that demonstrates this issue, that would be super helpful 🙏 |
Sorry I did not reply immediately, different timezone. |
Small update:
|
Here you go I managed to find what makes the difference. When you visit "/" which is inherited, or "/other" which is not, then for both the content type ends up being HTML. |
Excellent detective work, thank you! |
I think I have identified bug introduced in 2.1.0 and I've created PR #1649 to fix. Thanks again 👍 |
@jkowens ah nice! I’m glad I could help. I wish it took me less time to find what was special but it is not a trivial piece of code so I had to isolate many things to find the culprit. |
Hello,
Since I switched to version 2.1 then my JSON content type is served as text/html.
Could it be related to this old issue.
I am definitely in "development" RACK_ENV.
Didn't try production yet.
The text was updated successfully, but these errors were encountered: