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 log_headers option to globals #931

Merged
merged 1 commit into from
Aug 4, 2022
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
6 changes: 6 additions & 0 deletions lib/savon/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def initialize(options = {})
:namespaces => {},
:logger => Logger.new($stdout),
:log => false,
:log_headers => true,
:filters => [],
:pretty_print_xml => false,
:raise_errors => true,
Expand Down Expand Up @@ -219,6 +220,11 @@ def log_level(level)
@options[:logger].level = levels[level]
end

# To log headers or not.
def log_headers(log_headers)
@options[:log_headers] = log_headers
end

# A list of XML tags to filter from logged SOAP messages.
def filters(*filters)
@options[:filters] = filters.flatten
Expand Down
8 changes: 6 additions & 2 deletions lib/savon/request_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,21 @@ def log?
@globals[:log]
end

def log_headers?
@globals[:log_headers]
end

private

def log_request(request)
logger.info { "SOAP request: #{request.url}" }
logger.info { headers_to_log(request.headers) }
logger.info { headers_to_log(request.headers) } if log_headers?
logger.debug { body_to_log(request.body) }
end

def log_response(response)
logger.info { "SOAP response (status #{response.code})" }
logger.debug { headers_to_log(response.headers) }
logger.debug { headers_to_log(response.headers) } if log_headers?
logger.debug { body_to_log(response.body) }
end

Expand Down
20 changes: 20 additions & 0 deletions spec/savon/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,26 @@ def to_s
end
end

context "global :log_headers" do
it "instructs Savon to log SOAP requests and responses headers" do
stdout = mock_stdout {
client = new_client(:endpoint => @server.url, :log => true)
client.call(:authenticate)
}
soap_header = stdout.string.include? "Content-Type"
expect(soap_header).to be true
end

it "stops Savon from logging SOAP requests and responses headers" do
stdout = mock_stdout {
client = new_client(:endpoint => @server.url, :log => true, :log_headers => false)
client.call(:authenticate)
}
soap_header = stdout.string.include? "Content-Type"
expect(soap_header).to be false
end
end

context "global :ssl_version" do
it "sets the SSL version to use" do
HTTPI::Auth::SSL.any_instance.expects(:ssl_version=).with(:TLSv1).twice
Expand Down