Skip to content

add Content-Type header to the 405 response #343

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

Merged
merged 4 commits into from
Mar 4, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Next Release
* [#190](https://github.com/intridea/grape/issues/190): When you add a `GET` route for a resource, a route for the `HEAD` method will also be added automatically. You can disable this behavior with `do_not_route_head!` - [@dblock](http://github.com/dblock).
* Added `do_not_route_options!`, which disables the automatic creation of the `OPTIONS` route - [@dblock](http://github.com/dblock).
* [#335](https://github.com/intridea/grape/pull/335): Fix: request body parameters from a `PATCH` request not available in `params` - [@FreakenK](http://github.com/FreakenK).
* [#343](https://github.com/intridea/grape/pull/343): Fix: returning 405 with no Content-Type caused Rack to throw Rack::Lint::LintError - [@gustavosaume](https://github.com/gustavosaume) & [@wyattisimo](https://github.com/wyattisimo).
* Your contribution here.

0.2.6 (01/11/2013)
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ def add_head_not_allowed_methods
not_allowed_methods = %w(GET PUT POST DELETE PATCH HEAD) - methods
not_allowed_methods << "OPTIONS" if self.class.settings[:do_not_route_options]
not_allowed_methods.each do |bad_method|
@route_set.add_route( proc { [405, { 'Allow' => allow_header }, []]}, {
@route_set.add_route( proc { [405, { 'Allow' => allow_header, 'Content-Type' => 'text/plain' }, []]}, {
:path_info => path_info,
:request_method => bad_method
})
Expand Down
11 changes: 11 additions & 0 deletions spec/grape/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,17 @@ def subject.enable_root_route!
last_response.headers['Allow'].should eql 'OPTIONS, GET, POST, HEAD'
end

specify '405 responses includes an Content-Type header' do
subject.get 'example' do
"example"
end
subject.post 'example' do
"example"
end
put '/example'
last_response.headers['Content-Type'].should eql 'text/plain'
end

it 'adds an OPTIONS route that returns a 204 and an Allow header' do
subject.get 'example' do
"example"
Expand Down