Skip to content

Commit

Permalink
Fix: Remove xmlns:wsa's already added elsewhere; select Content-Type …
Browse files Browse the repository at this point in the history
…HTTP header based on SOAP version (#868)

* remove unneeded xmlns:wsa, already added elsewhere
* clean up Content-Type header and add MIME-Version
* select header Content-Type based on SOAP version
* xmlns:wsa attribute is not needed on wsa:MessageID. it's already included in the header

Co-authored-by: Olle Jonsson <olle.jonsson@gmail.com>
  • Loading branch information
armstrtw and olleolleolle authored Jul 5, 2020
1 parent 49a0d2b commit b2b545a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 22 deletions.
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 = {
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

0 comments on commit b2b545a

Please sign in to comment.