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

Fix: Remove xmlns:wsa's already added elsewhere; select Content-Type HTTP header based on SOAP version #868

Merged
merged 5 commits into from
Jul 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions lib/savon/header.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,7 @@ def build_wsa_header
convert_to_xml({
'wsa:Action' => @locals[:soap_action],
'wsa:To' => @globals[:endpoint],
'wsa:MessageID' => "urn:uuid:#{SecureRandom.uuid}",
attributes!: {
'wsa:MessageID' => {
"xmlns:wsa" => "http://schemas.xmlsoap.org/ws/2004/08/addressing"
}
}
'wsa:MessageID' => "urn:uuid:#{SecureRandom.uuid}"
})
end

Expand Down
20 changes: 14 additions & 6 deletions lib/savon/operation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
module Savon
class Operation

SOAP_REQUEST_TYPE = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could call it content types in the name, I guess.

1 => "text/xml",
2 => "application/soap+xml"
}

def self.create(operation_name, wsdl, globals)
if wsdl.document?
ensure_name_is_symbol! operation_name
Expand Down Expand Up @@ -95,16 +100,19 @@ def build_request(builder)
request.url = endpoint
request.body = builder.to_s

if builder.multipart
request.gzip
request.headers["Content-Type"] = ["multipart/related",
"type=\"#{SOAP_REQUEST_TYPE[@globals[:soap_version]]}\"",
"start=\"#{builder.multipart[:start]}\"",
"boundary=\"#{builder.multipart[:multipart_boundary]}\""].join("; ")
request.headers["MIME-Version"] = "1.0"
end

# TODO: could HTTPI do this automatically in case the header
# was not specified manually? [dh, 2013-01-04]
request.headers["Content-Length"] = request.body.bytesize.to_s

if builder.multipart
request.headers["Content-Type"] = "multipart/related; " \
"boundary=\"#{builder.multipart[:multipart_boundary]}\"; " \
"type=\"text/xml\"; start=\"#{builder.multipart[:start]}\""
end

request
end

Expand Down
10 changes: 0 additions & 10 deletions spec/savon/message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,6 @@
end
end
end

context 'wsa:MessageID' do
let(:message_id_tag) {
'<wsa:MessageID xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">'
}
it 'should include xmlns:wsa attribute' do
response = client.call(:something, message: {})
expect(response.xml).to include(message_id_tag)
end
end
end

end