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

Use 415 status for request bodies of unsupported media type #1765

Merged
merged 1 commit into from
Jun 6, 2018

Conversation

jdmurphy
Copy link
Contributor

@jdmurphy jdmurphy commented Jun 4, 2018

Noticed that for requests where bodies are present (i.e. PUT, POST, PATCH, etc.), that if the content type header was something unsupported that a 406 would be returned. Reading over the original RFC 2616, a 415 should be used when a request entity is not in a supported format, but currently a 406 is returned. It seems like it should be as simple as changing this logic.

@dblock
Copy link
Member

dblock commented Jun 4, 2018

That is probably correct, but is a backwards incompatible change.

At the very least it needs to have a section in https://github.com/ruby-grape/grape/blob/master/UPGRADING.md, please.

@@ -948,7 +948,7 @@ def app
params[:user]
end
put '/request_body', '<user>Bobby T.</user>', 'CONTENT_TYPE' => 'application/xml'
expect(last_response.status).to eq(406)
expect(last_response.status).to eq(415)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description of this test is now incorrect.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed: d571f25

@dblock
Copy link
Member

dblock commented Jun 4, 2018

Does this need more test scenarios? With or without body for example?

@jdmurphy
Copy link
Contributor Author

jdmurphy commented Jun 4, 2018

@dblock, I agree it could probably use more tests. Do you have a preference/idea of where you want them. The tests that failed are actually just in a #params testing block which doesn't seem like the best place, but the formatter_spec also doesn't really have anything like that.

Also, I can update the UPGRADING document, but where should I put it (in terms of heading)? Should I assume a 2.x release? Will this need to sit in a 2.x feature branch until any other planned or unplanned non-passive changes are in?

@dblock
Copy link
Member

dblock commented Jun 4, 2018

No strong opinions on test locations, but definitely in specs :) Maybe something new.

It doesn't need to sit in a branch, just keep updating the PR. I think we should do 1.1, Grape hasn't been using the major version, we've spent years getting to 1.0. Appreciate any thoughts on that too, maybe this is where we just use semantic versioning properly?

@jdmurphy
Copy link
Contributor Author

jdmurphy commented Jun 5, 2018

@dblock, I ended up adding them to the formatter_spec in d2e2f7e (removed my accidental require pry addition in 3c7df26); I grouped it with some similar logic around the correct methods and reading of the body into the rack request form hash. Let me know what you think.

@dblock
Copy link
Member

dblock commented Jun 5, 2018

This looks good. Maybe squash it if you don't mind?

I want to leave this open for a bit, maybe @namusyaka or @dm1try could pitch in that we want to do this?

@jdmurphy
Copy link
Contributor Author

jdmurphy commented Jun 5, 2018

@dblock, squashed all the things.

Copy link
Member

@dm1try dm1try left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dm1try
Copy link
Member

dm1try commented Jun 5, 2018

as for versioning

I think we should do 1.1

I agree, up to 1.1.0 and add "incompatibility" note in UPGRADING.md

Grape does not claim that it uses SemVer, so for such incompatible fix is fine :) (moreover, this way is common in Ruby/Rails community itself, at least for now)

@@ -95,7 +95,7 @@ def read_rack_input(body)
fmt = request.media_type ? mime_types[request.media_type] : options[:default_format]

unless content_type_for(fmt)
throw :error, status: 406, message: "The requested content-type '#{request.media_type}' is not supported."
throw :error, status: 415, message: "The requested content-type '#{request.media_type}' is not supported."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpicking, but I would change the message (ex. from "requested" to "provided") to clarify the difference between 406/415

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, rebased and pushed as a single commit

@dblock
Copy link
Member

dblock commented Jun 5, 2018

@jdmurphy can you please do the version bump and the upgrading part of this? thx

@jdmurphy
Copy link
Contributor Author

jdmurphy commented Jun 5, 2018

@dblock when you say do the version bump, what did you mean? Like update the version file to be 1.1.0 and update the changelog and upgrading doc to reflect the new version there as well?

@jdmurphy
Copy link
Contributor Author

jdmurphy commented Jun 5, 2018

I updated the version file, README, UPGRADING and CHANGELOG, and then rebased and pushed.

@dblock dblock merged commit 2dcef9a into ruby-grape:master Jun 6, 2018
@dblock
Copy link
Member

dblock commented Jun 6, 2018

Merged. Great work @jdmurphy and thanks!

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

Successfully merging this pull request may close these issues.

3 participants