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

Add support for local request headers #742

Merged
merged 1 commit into from
Feb 19, 2016
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
3 changes: 2 additions & 1 deletion lib/savon/operation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def build_request(builder)

request = SOAPRequest.new(@globals).build(
:soap_action => soap_action,
:cookies => @locals[:cookies]
:cookies => @locals[:cookies],
:headers => @locals[:headers]
)

request.url = endpoint
Expand Down
4 changes: 4 additions & 0 deletions lib/savon/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -406,5 +406,9 @@ def response_parser(parser)
def multipart(multipart)
@options[:multipart] = multipart
end

def headers(headers)
@options[:headers] = headers
end
end
end
5 changes: 3 additions & 2 deletions lib/savon/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def build(options = {})
configure_proxy
configure_cookies options[:cookies]
configure_timeouts
configure_headers options[:soap_action]
configure_headers options[:soap_action], options[:headers]
configure_ssl
configure_auth
configure_redirect_handling
Expand All @@ -88,8 +88,9 @@ def configure_cookies(cookies)
@http_request.set_cookies(cookies) if cookies
end

def configure_headers(soap_action)
def configure_headers(soap_action, headers)
@http_request.headers = @globals[:headers] if @globals.include? :headers
@http_request.headers.merge!(headers) if headers
@http_request.headers["SOAPAction"] ||= %{"#{soap_action}"} if soap_action
@http_request.headers["Content-Type"] ||= CONTENT_TYPE[@globals[:soap_version]] % @globals[:encoding]
end
Expand Down
11 changes: 11 additions & 0 deletions spec/savon/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,17 @@ def to_s
end
end

context "request :headers" do
it "sets headers" do
client = new_client(:endpoint => @server.url(:inspect_request))

response = client.call(:authenticate, :headers => { "X-Token" => "secret" })
x_token = inspect_request(response).x_token

expect(x_token).to eq("secret")
end
end

def new_client(globals = {}, &block)
globals = { :wsdl => Fixture.wsdl(:authentication), :log => false }.merge(globals)
Savon.client(globals, &block)
Expand Down