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

Header version ignored #133

Closed
pduersteler opened this issue Feb 2, 2012 · 12 comments
Closed

Header version ignored #133

pduersteler opened this issue Feb 2, 2012 · 12 comments

Comments

@pduersteler
Copy link

This may be similiar to #124 and #74

According to several slides and docs and wiki pages, I tried this:

version 'v2', :using => :header, :strict => true, :vendor => 'test'

resource :test do
    get :first do
        "v2"
    end
end


version 'v1', :using => :header, :strict => true, :vendor => 'test'

resource :test do
    get :first do
        "v1"
    end
end
curl -H Accept=application/vnd.test-v1+json http://test.localhost.example:3000/api/test/first
curl -H Accept=application/vnd.test-v2+json http://test.localhost.example:3000/api/test/first

The requests above always returns "v2" regardless of the header being set. I also tested those without using the strict param, but got the same results.

@dblock
Copy link
Member

dblock commented Feb 2, 2012

Grape from the frontier branch or shipped version?

@pduersteler
Copy link
Author

tried the shipped version, explicit master branch and frontier branch.

@ghost ghost assigned jch Feb 7, 2012
@rodzyn
Copy link
Contributor

rodzyn commented Feb 14, 2012

Try this:

curl -H "Accept: application/vnd.test-v1+json" http://test.localhost.example:3000/api/test/first
curl -H "Accept: application/vnd.test-v2+json" http://test.localhost.example:3000/api/test/first

It will be as you expected.

I don't know whether it's a but in curl on OS X or not, but my version of curl does not support grape-wiki-way of passing headers too :) (it assumes accept header as asterisk/asterisk, that's why you have always 'v2')

@pduersteler
Copy link
Author

Thats what I've tried on my linux box and I always got response from v2.
Am 14.02.2012 22:24 schrieb "Marcin Olichwirowicz" <
reply@reply.github.com

:

Try this:

curl -H "Accept: application/vnd.test-v1+json"
http://test.localhost.example:3000/api/test/first
curl -H "Accept: application/vnd.test-v2+json"
http://test.localhost.example:3000/api/test/first

It will be as you expected.

I don't know whether it's a but in curl on OS X or not, but my version of
curl does not support grape-wiki-way of passing headers too :) (it assumes
accept header as asterisk/asterisk, that's why you have always 'v2')


Reply to this email directly or view it on GitHub:
#133 (comment)

@dblock
Copy link
Member

dblock commented Feb 19, 2012

With pull #144 it's doing the correct thing on frontier. If you're still having this issue, reopen it and post the output from curl -v (double-check that the Accept header is included properly).

@dblock dblock closed this as completed Feb 19, 2012
@seanmoon
Copy link
Contributor

I'm also having a problem with enabling the versioning in Grape.

I've created a new Rails 3.2.9 project with Grape 0.2.2 included here: https://github.com/seanmoon/grape-versioning-example

The output from curl is included in the README and there is also a spec demonstrating the issue that you can run via rspec.

In my actual project, I'd like to include V1 and V2 via separate source files, but even in this more simplified situation I'm running into an issue.

Any suggestions or help would be appreciated.

Here's the source for the API.

https://github.com/seanmoon/grape-versioning-example/blob/master/app/api/api.rb

@dblock
Copy link
Member

dblock commented Dec 20, 2012

I'll just reopen this.

@dblock dblock reopened this Dec 20, 2012
@dblock
Copy link
Member

dblock commented Dec 28, 2012

I'll try to take a look at this soon-ish. A failing spec for this would be ideal of course.

@seanmoon
Copy link
Contributor

seanmoon commented Jan 3, 2013

Looks like the issue I'm seeing only happens when the prefix has been specified.

I've written a failing spec here: https://github.com/seanmoon/grape
Relevant (and only) changed file: seanmoon@3c1e695

The specs are also failing using path and params so it seems to be not limited to using a header if my test is failing properly.

In my example project I get a 404 when I should be getting a matching version. I am seeing the same behavior with this failing spec I wrote. I wasn't able to quickly deduce where this issue is manifesting in the code. Perhaps you would have a better idea where to start.

dblock added a commit to dblock/grape that referenced this issue Jan 4, 2013
@dblock
Copy link
Member

dblock commented Jan 5, 2013

cc: @jwkoelewijn who has implemented a lot of this code, I could use some help

@dblock
Copy link
Member

dblock commented Jan 5, 2013

Fixed in 548ceb4

Thanks @seanmoon for the spec, you're correct, it was broken when using prefix.

Header-based versioning works by mounting every version in an identical path, including the prefix. If the version doesn't match from the header, the next one will be tried. With the prefixer middleware we would strip the prefix from PATH_INFO, so the next route would no longer match the path and therefore produce a 404.

@dblock dblock closed this as completed Jan 5, 2013
dblock added a commit to dblock/grape that referenced this issue Jan 5, 2013
…ltered with path versioning. Got rid of the prefixer middleware, which is not generic across versioning schemes, but specific to the path versioner.
@seanmoon
Copy link
Contributor

seanmoon commented Jan 7, 2013

Awesome, thanks!

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

No branches or pull requests

5 participants