lib/savon/request.rb in savon-0.7.0 vs lib/savon/request.rb in savon-0.7.1
- old
+ new
@@ -58,10 +58,20 @@
attr_reader :endpoint
# Returns the proxy URI.
attr_reader :proxy
+ # Returns the HTTP headers for a SOAP request.
+ def headers
+ @headers ||= {}
+ end
+
+ # Sets the HTTP headers for a SOAP request.
+ def headers=(headers)
+ @headers = headers if headers.kind_of? Hash
+ end
+
# Sets the +username+ and +password+ for HTTP basic authentication.
def basic_auth(username, password)
@basic_auth = [username, password]
end
@@ -96,11 +106,11 @@
private
# Logs the SOAP request.
def log_request
log "SOAP request: #{@soap.endpoint}"
- log http_header.map { |key, value| "#{key}: #{value}" }.join(", ")
+ log headers.merge(soap_headers).map { |key, value| "#{key}: #{value}" }.join(", ")
log @soap.to_xml
end
# Logs the SOAP response.
def log_response
@@ -111,11 +121,11 @@
# Returns a Net::HTTP request for a given +type+. Yields the request
# to an optional block.
def request(type)
request = case type
when :wsdl then Net::HTTP::Get.new wsdl_endpoint
- when :soap then Net::HTTP::Post.new @soap.endpoint.path, http_header
+ when :soap then Net::HTTP::Post.new @soap.endpoint.path, headers.merge(soap_headers)
end
request.basic_auth *@basic_auth if @basic_auth
yield request if block_given?
request
end
@@ -124,11 +134,11 @@
def wsdl_endpoint
return @endpoint.path unless @endpoint.query
"#{@endpoint.path}?#{@endpoint.query}"
end
- # Returns a Hash containing the header for an HTTP request.
- def http_header
+ # Returns a Hash containing the SOAP headers for an HTTP request.
+ def soap_headers
{ "Content-Type" => ContentType[@soap.version], "SOAPAction" => @soap.action }
end
# Logs a given +message+.
def log(message)