提交 8404ed64 编写于 作者: S Sean Griffin

Merge pull request #17928 from sergey-alekseev/remove-unused-form-data-method

......@@ -306,10 +306,16 @@ def body
end
end
# Returns true if the request's content MIME type is
# +application/x-www-form-urlencoded+ or +multipart/form-data+.
# Determine whether the request body contains form-data by checking
# the request Content-Type for one of the media-types:
# "application/x-www-form-urlencoded" or "multipart/form-data". The
# list of form-data media types can be modified through the
# +FORM_DATA_MEDIA_TYPES+ array.
#
# A request body is not assumed to contain form-data when no
# Content-Type header is provided and the request_method is POST.
def form_data?
FORM_DATA_MEDIA_TYPES.include?(content_mime_type.to_s)
FORM_DATA_MEDIA_TYPES.include?(media_type)
end
def body_stream #:nodoc:
......
......@@ -1212,3 +1212,23 @@ def setup
end
end
end
class RequestFormData < BaseRequestTest
test 'media_type is from the FORM_DATA_MEDIA_TYPES array' do
assert stub_request('CONTENT_TYPE' => 'application/x-www-form-urlencoded').form_data?
assert stub_request('CONTENT_TYPE' => 'multipart/form-data').form_data?
end
test 'media_type is not from the FORM_DATA_MEDIA_TYPES array' do
assert !stub_request('CONTENT_TYPE' => 'application/xml').form_data?
assert !stub_request('CONTENT_TYPE' => 'multipart/related').form_data?
end
test 'no Content-Type header is provided and the request_method is POST' do
request = stub_request('REQUEST_METHOD' => 'POST')
assert_equal '', request.media_type
assert_equal 'POST', request.request_method
assert !request.form_data?
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册