HTTP_ACCEPT doesn't allows extra attributes for MIME TYPE application/json #3390

Closed
antek-drzewiecki opened this Issue Oct 21, 2011 · 4 comments

Projects

None yet

3 participants

@antek-drzewiecki

Some mobile phone providers add compression parameters in their Accept request Headers. This might cause the application to respond with HTML instead of JSON.

I recently came across the following format for application/json:
HEADER KEY: HTTP_ACCEPT
HEADER VALUE: application/json,/;q=0.001

The rails application will translate this Accept header to html/text
HEADER KEY: action_dispatch.request.formats
HEADER VALUE: text/html

The value application/json for HTTP_ACCESS should give a json callback.
I fixed the issue in my application by forcing the request format to application/json in the ApplicationController. But a more appropriate solution would be welcome.


class ApplicationController < ActionController::Base
before_filter :foo
def foo
request.format = 'json'.to_sym if ((request.env["HTTP_ACCEPT"]).include? "application/json")
end

But proper handling would be better if the application/json,/;q=0.001 syntax is correct.

@ahawkins

@steveklabnik didn't you fix this in a different commit?

@steveklabnik
Ruby on Rails member

What I did was add support for non-q parameters (8c4b3a4), so yes, I think that would take care of it.

@Antek-drzewiecki, is this still an issue for you on master?

@antek-drzewiecki

I was running rails 3.0.9. Ill test it on the master branch on monday.

@steveklabnik
Ruby on Rails member

@Antek-drzewiecki cool. If there's still an issue on 3.2 or master, let me know, and re-open. Since I'm pretty sure that I fixed this, I'm gonna give it a close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment