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

Adding */* to Accept header seems to override other formats #18676

Closed
iangreenleaf opened this issue Jan 25, 2015 · 2 comments
Closed

Adding */* to Accept header seems to override other formats #18676

iangreenleaf opened this issue Jan 25, 2015 · 2 comments

Comments

@iangreenleaf
Copy link
Contributor

This deals with a similar area as #4127, but the symptoms seem different enough that I thought it deserved its own bug. Hopefully I'm not wrong.

Make an endpoint that only responds to a particular MIME type, such as JSON:

  # GET /users.json
  def index
    respond_to do |format|
      format.json {
        @users = User.all
      }
    end
  end

We can make requests against this as long as we have something compatible in the Accept header:

$ curl -I -H"Accept: application/json" http://localhost:3001/users #=> HTTP/1.1 200 OK 
$ curl -I -H"Accept: application/json, foo/bar" http://localhost:3001/users #=> HTTP/1.1 200 OK
$ curl -I -H"Accept: application/json, foo/*" http://localhost:3001/users #=> HTTP/1.1 200 OK 
$ curl -I -H"Accept: application/*, foo/bar" http://localhost:3001/users #=> HTTP/1.1 200 OK 
$ curl -I -H"Accept: */*" http://localhost:3001/users #=> HTTP/1.1 200 OK 

But using */* in combination with a valid format somehow screws it up and causes it to try to force the format to text/html, which then fails when the action won't respond as such.

$ curl -I -H"Accept: application/json, */*" http://localhost:3001/users #=> HTTP/1.1 406 Not Acceptable 

Here's a simple Rails app that can reproduce the issue.. The users#index endpoint can be hit as in my above examples.

@sgrif
Copy link
Contributor

sgrif commented Jan 25, 2015

I'm almost certain this is intentional. I looked into this a long while ago, and if you look hard enough you'll find previous discussions about this issue (sorry, I don't have a link) but it involves browsers not actually following the spec on properly specifying their Accept header, Safari in particular being problematic.

@pixeltrix
Copy link
Contributor

Duplicate of #8987 - see there for discussion of why it happens

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

3 participants