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

Enable handling of multipart/form-data content #791

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 0 additions & 8 deletions lib/webmock/request_pattern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,6 @@ def initialize(pattern)
end

def matches?(body, content_type = "")
assert_non_multipart_body(content_type)

if (@pattern).is_a?(Hash)
return true if @pattern.empty?
matching_body_hashes?(body_as_hash(body, content_type), @pattern, content_type)
Expand Down Expand Up @@ -314,12 +312,6 @@ def body_format(content_type)
BODY_FORMATS[normalized_content_type]
end

def assert_non_multipart_body(content_type)
if content_type =~ %r{^multipart/form-data}
raise ArgumentError.new("WebMock does not support matching body for multipart/form-data requests yet :(")
end
end

# Compare two hashes for equality
#
# For two hashes to match they must have the same length and all
Expand Down
11 changes: 11 additions & 0 deletions lib/webmock/request_signature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ def json_headers?
def assign_options(options)
self.body = options[:body] if options.has_key?(:body)
self.headers = options[:headers] if options.has_key?(:headers)

if headers && body then
if content_type = headers['Content-Type'] then
content_type, boundary = content_type.split(';')
if boundary && boundary =~ /^\s*boundary=([a-z0-9]+)$/i then
boundary_string = $1
self.body.gsub!(boundary_string, '<<<boundary>>>')
self.headers['Content-Type'].gsub!(boundary_string, '<<<boundary>>>')
end
end
end
end

end
Expand Down