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
POST with non-urlencoded data fails when request does not specify a content-type #804
Comments
Related: #514 |
Investigating. |
Sorry for taking such a long time for this. This is the very reason: https://github.com/rack/rack/blob/master/lib/rack/request.rb#L33 To work properly, def content_type
content_type = @env['CONTENT_TYPE']
content_type.nil? || content_type.empty? ? 'application/octet-stream' : content_type
end I suppose I should send a PR to |
Closing this here, as it's a Rack bug. |
@hbf I also hit this bug and participated on the pull request for Rack. I don't think it's realistic to get this changed in Rack so long as they're not breaking major version compatibility. The workaround that I've validated works, and I would suggest is to use the following middleware in your Protobuf HTTP servers: class DefaultContentTypeMiddleware
def initialize(app)
@app = app
end
def call(env)
# Default to the 'application/octet-stream' content type if one is not set.
if env['CONTENT_TYPE'].nil? || env['CONTENT_TYPE'].empty?
env['CONTENT_TYPE'] = 'application/octet-stream'
end
@app.call(env)
end
end You could even go so far as to default to |
I am doing a POST to a Sinatra application:
The effect of the
-H "Content-Type:"
is that my request does not contain aContent-Type
header (see output below). The data I post is a binary Protobuf message (and thus not of typeapplication/x-www-form-urlencoded
).I get the following error:
It seems that Sinatra is trying to urldecode the request body. According to the HTTP Spec, a server should assume
application/octet-stream
if no content-type is given.The request works fine when I add to
curl
the option-H "Content-Type: application/octet-stream"
.The text was updated successfully, but these errors were encountered: