-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Handle EOFError raised by Rack #2161
Changes from 1 commit
f405ecb
08bb693
c1dd89a
ca030b1
e9fb53e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -420,6 +420,22 @@ def app | |
expect(last_response.status).to eq(201) | ||
expect(last_response.body).to eq('Bob') | ||
end | ||
|
||
it 'returns a 400 if given an invalid multipart body' do | ||
# Rack swallowed this error until v2.2.0 | ||
major, minor, _patch = Rack.release.split('.').map(&:to_i) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The "correct" way to do this is to use Let's also externalize the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! I figured there had to be a better way. |
||
next if major < 2 || major == 2 && minor < 2 | ||
|
||
subject.params do | ||
requires :file, type: Rack::Multipart::UploadedFile | ||
end | ||
subject.post '/upload' do | ||
params[:file][:filename] | ||
end | ||
post '/upload', { file: '' }, 'CONTENT_TYPE' => 'multipart/form-data; boundary=foobar' | ||
expect(last_response.status).to eq(400) | ||
expect(last_response.body).to include('multipart/form-data') | ||
end | ||
end | ||
|
||
it 'responds with a 415 for an unsupported content-type' do | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am concerned that this is hardcoding
multipart/form-data
, input doesn't have to be this way, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know when Rack would raise this error other than when given a
multipart/form-data
, but I'm not a Rack expert. I've pushed a commit to use the object'scontent_type
method instead.This error class seemed the most appropriated, but it requires a content type. I'm happy to create a different error class if that would be preferable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ok with reusing this error, it makes sense to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On a second thought, should we create a EmptyMessageBody error?