From 3208f2580b9c7bf0857f9331a33caa89cf937f39 Mon Sep 17 00:00:00 2001 From: Chris Griego Date: Wed, 22 Sep 2010 23:42:36 -0500 Subject: [PATCH] Ensure the unencoded response body is what gets logged --- lib/savon/client.rb | 2 +- lib/savon/request.rb | 8 ++++---- spec/savon/request_spec.rb | 26 ++++++++++++++++++++++---- spec/support/endpoint_helper.rb | 1 + spec/support/http_stubs.rb | 4 ++++ 5 files changed, 32 insertions(+), 9 deletions(-) diff --git a/lib/savon/client.rb b/lib/savon/client.rb index a51e368d..e090d985 100644 --- a/lib/savon/client.rb +++ b/lib/savon/client.rb @@ -101,7 +101,7 @@ def method_missing(method, *args, &block) #:doc: super unless @wsdl.respond_to? soap_action setup_objects *@wsdl.operation_from(soap_action), &block - Response.new @request.soap(@soap) + @request.soap(@soap) end # Expects a SOAP operation Hash and sets up Savon::SOAP and Savon::WSSE. Yields them to a given diff --git a/lib/savon/request.rb b/lib/savon/request.rb index 80bc48a5..6ab44343 100644 --- a/lib/savon/request.rb +++ b/lib/savon/request.rb @@ -103,9 +103,9 @@ def soap(soap) http.use_ssl = @soap.endpoint.ssl? log_request - @response = http.start do |h| + @response = Response.new(http.start do |h| h.request request(:soap) { |request| request.body = @soap.to_xml } - end + end) log_response @response end @@ -126,8 +126,8 @@ def log_request # Logs the SOAP response. def log_response - log "SOAP response (status #{@response.code}):" - log @response.body + log "SOAP response (status #{@response.http.code}):" + log @response.to_s end # Returns a Net::HTTP request for a given +type+. Yields the request to an optional block. diff --git a/spec/savon/request_spec.rb b/spec/savon/request_spec.rb index 1d49d3f4..148ea3ae 100644 --- a/spec/savon/request_spec.rb +++ b/spec/savon/request_spec.rb @@ -77,17 +77,18 @@ describe "when executing a SOAP request" do + let(:fixture) { nil } before :each do operation = WSDLFixture.authentication(:operations)[:authenticate] action, input = operation[:action], operation[:input] - @soap = Savon::SOAP.new action, input, EndpointHelper.soap_endpoint + @soap = Savon::SOAP.new action, input, EndpointHelper.soap_endpoint(fixture) end - it "should return the Net::HTTP response" do + it "should return the Savon response" do soap_response = @request.soap @soap - soap_response.should be_a(Net::HTTPResponse) - soap_response.body.should == ResponseFixture.authentication + soap_response.should be_a(Savon::Response) + soap_response.http.body.should == ResponseFixture.authentication end it "should include Accept-Encoding gzip if it is enabled" do @@ -107,6 +108,23 @@ @request.soap @soap end + + describe "the logger" do + before { Savon::Request.log = true } + after { Savon::Request.log = false } + let(:fixture) { :gzip } + + it "logs the response XML when gzip is enabled" do + @request = Savon::Request.new :wsdl => EndpointHelper.wsdl_endpoint(fixture), :gzip => true + a_post = Net::HTTP::Post.new(@soap.endpoint.request_uri, {}) + + @request.expects(:log).with(anything).at_least(4) + @request.expects(:log).with(GzipResponseFixture.message).never + @request.expects(:log).with("A short gzip encoded message\n").once + + @request.soap @soap + end + end end it "should not include host when creating HTTP requests" do diff --git a/spec/support/endpoint_helper.rb b/spec/support/endpoint_helper.rb index 2c357784..daa19fc8 100644 --- a/spec/support/endpoint_helper.rb +++ b/spec/support/endpoint_helper.rb @@ -16,6 +16,7 @@ def self.soap_endpoint(type = nil) when :soap_fault then "http://soapfault.example.com/Service?wsdl" when :http_error then "http://httperror.example.com/Service?wsdl" when :invalid then "http://invalid.example.com/Service?wsdl" + when :gzip then "http://gzip.example.com/Service?wsdl" else "http://example.com/validation/1.0/AuthenticationService" end end diff --git a/spec/support/http_stubs.rb b/spec/support/http_stubs.rb index 31f61378..a07d2cf6 100644 --- a/spec/support/http_stubs.rb +++ b/spec/support/http_stubs.rb @@ -4,6 +4,10 @@ FakeWeb.register_uri :get, EndpointHelper.wsdl_endpoint, :body => WSDLFixture.authentication FakeWeb.register_uri :post, EndpointHelper.soap_endpoint, :body => ResponseFixture.authentication +# Some WSDL and SOAP request. +FakeWeb.register_uri :get, EndpointHelper.wsdl_endpoint(:gzip), :body => WSDLFixture.authentication +FakeWeb.register_uri :post, EndpointHelper.soap_endpoint(:gzip), :body => GzipResponseFixture.message + # WSDL and SOAP request with a Savon::SOAPFault. FakeWeb.register_uri :get, EndpointHelper.wsdl_endpoint(:soap_fault), :body => WSDLFixture.authentication FakeWeb.register_uri :post, EndpointHelper.soap_endpoint(:soap_fault), :body => ResponseFixture.soap_fault