Skip to content

Commit

Permalink
Merge pull request #683 from shekibobo/feature/allow-host-override
Browse files Browse the repository at this point in the history
Allow overriding host in WSDL actions
  • Loading branch information
tjarratt committed May 20, 2015
2 parents 835b2dd + f6d827f commit b5b6e47
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/savon/operation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,13 @@ def soap_action
end

def endpoint
@globals[:endpoint] || @wsdl.endpoint
@globals[:endpoint] || @wsdl.endpoint.tap do |url|
if @globals[:host]
host_url = URI.parse(@globals[:host])
url.host = host_url.host
url.port = host_url.port
end
end
end

def raise_expected_httpi_response!
Expand Down
8 changes: 7 additions & 1 deletion lib/savon/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ def initialize(options = {})
:use_wsa_headers => false,
:no_message_tag => false,
:follow_redirects => false,
:unwrap => false
:unwrap => false,
:host => nil
}

options = defaults.merge(options)
Expand All @@ -108,6 +109,11 @@ def wsdl(wsdl_address)
@options[:wsdl] = wsdl_address
end

# set different host for actions in WSDL
def host(host)
@options[:host] = host
end

# SOAP endpoint.
def endpoint(endpoint)
@options[:endpoint] = endpoint
Expand Down
9 changes: 9 additions & 0 deletions spec/savon/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@
end
end

context "global :host" do
it "overrides the WSDL endpoint host" do
client = new_client(:wsdl => Fixture.wsdl(:no_message_tag), host: "https://example.com:8080")

request = client.build_request(:update_orders)
expect(request.url.to_s).to eq "https://example.com:8080/webserviceexternal/contracts.asmx"
end
end

context "global :headers" do
it "sets the HTTP headers for the next request" do
client = new_client(:endpoint => @server.url(:inspect_request), :headers => { "X-Token" => "secret" })
Expand Down

0 comments on commit b5b6e47

Please sign in to comment.