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

Allow to skip reading body of input so route can accept all sort of content types #344

Closed
wants to merge 1 commit into from

Conversation

TomasLinhart
Copy link

This is useful for implementing routes that are used for uploading files.

@dblock
Copy link
Member

dblock commented Feb 22, 2013

This needs at least a test, but I am not sure this is such a great idea. For one, Rack will parse input depending on content-type anyway for multipart data. Can you maybe describe the entire scenario?

@TomasLinhart
Copy link
Author

@dblock
Copy link
Member

dblock commented Feb 22, 2013

There're several things going on:

  1. There're types that want to be read and parsed, such as JSON, when your API supports JSON.
  2. There're types that we're not aware of that we would like to just read, without parsing. This is a new feature request because right now we throw a 406 inside read_body_input.
  3. There're cases when we just don't want to parse any input, completely.

I think (3) is very questionable. When you send garbage to the server and say "this is JSON", I interpret the RFC as saying "raise an error". If I am right, then (3) is incorrect - this is your proposed implementation.

On the other hand, (2) will solve your problem as well without changing anything to the behavior of existing parsers. There're several nice ways to express this in a DSL. One idea could be parser :other, SomeParserThatDoesNothing, but that's quite ugly. I think a nice way to solve this could be a content_type :any option that would set a generic noop parser and a generic noop formatter - I would love a pull request for that.

@dblock dblock closed this in bcf18e1 Apr 14, 2013
@dblock
Copy link
Member

dblock commented Apr 14, 2013

I've implemented (2), you can now do parser :json, nil, which will disable parsing for a given content-type. The only remaining case is when you have a client sending you data without a content-type, that's ambiguous and we'll return a 406 in this case. I feel pretty strongly about keeping it this way, I don't see any real scenarios where an API should not behave this way. Happy to be convinced otherwise.

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.

2 participants