diff --git a/lib/httplog/adapters/ethon.rb b/lib/httplog/adapters/ethon.rb index f1e5a28..14dd395 100644 --- a/lib/httplog/adapters/ethon.rb +++ b/lib/httplog/adapters/ethon.rb @@ -11,7 +11,7 @@ def http_request(url, action_name, options = {}) if HttpLog.url_approved?(url) HttpLog.log_request(action_name, url) HttpLog.log_headers(options[:headers]) - HttpLog.log_data(options[:body]) #if action_name == :post + HttpLog.log_data(options[:body], options[:headers]['Content-Type']) #if action_name == :post end orig_http_request(url, action_name, options) diff --git a/lib/httplog/adapters/excon.rb b/lib/httplog/adapters/excon.rb index a1b1778..9d2a09d 100644 --- a/lib/httplog/adapters/excon.rb +++ b/lib/httplog/adapters/excon.rb @@ -42,7 +42,7 @@ def request_call(datum) if HttpLog.url_approved?(url) HttpLog.log_request(datum[:method], _httplog_url(datum)) HttpLog.log_headers(datum[:headers]) - HttpLog.log_data(datum[:body])# if datum[:method] == :post + HttpLog.log_data(datum[:body], datum[:headers]['Content-Type'])# if datum[:method] == :post end orig_request_call(datum) end diff --git a/lib/httplog/adapters/http.rb b/lib/httplog/adapters/http.rb index 9b1f6ea..66dc10f 100644 --- a/lib/httplog/adapters/http.rb +++ b/lib/httplog/adapters/http.rb @@ -14,7 +14,7 @@ class Client if log_enabled HttpLog.log_request(req.verb, req.uri) HttpLog.log_headers(req.headers.to_h) - HttpLog.log_data(req.body) #if req.verb == :post + HttpLog.log_data(req.body, req.headers.to_h['Content-Type']) #if req.verb == :post end bm = Benchmark.realtime do diff --git a/lib/httplog/adapters/httpclient.rb b/lib/httplog/adapters/httpclient.rb index 272a39e..5de8660 100644 --- a/lib/httplog/adapters/httpclient.rb +++ b/lib/httplog/adapters/httpclient.rb @@ -9,7 +9,7 @@ def do_get_block(req, proxy, conn, &block) if log_enabled HttpLog.log_request(req.header.request_method, req.header.request_uri) HttpLog.log_headers(req.headers) - HttpLog.log_data(req.body) + HttpLog.log_data(req.body, req.headers['Content-Type']) end retryable_response = nil diff --git a/lib/httplog/adapters/patron.rb b/lib/httplog/adapters/patron.rb index 174b33c..fe8709b 100644 --- a/lib/httplog/adapters/patron.rb +++ b/lib/httplog/adapters/patron.rb @@ -8,7 +8,7 @@ def request(action_name, url, headers, options = {}) if log_enabled HttpLog.log_request(action_name, url) HttpLog.log_headers(headers) - HttpLog.log_data(options[:data])# if action_name == :post + HttpLog.log_data(options[:data], headers['Content-Type'])# if action_name == :post end bm = Benchmark.realtime do diff --git a/lib/httplog/http_log.rb b/lib/httplog/http_log.rb index 78a360e..0eb222e 100644 --- a/lib/httplog/http_log.rb +++ b/lib/httplog/http_log.rb @@ -95,8 +95,12 @@ def log_body(body, encoding = nil, content_type=nil) end - def log_data(data) + def log_data(data, content_type = nil) return if config.compact_log || !config.log_data + unless text_based?(content_type) + log("Data: (not showing binary data)") + return + end data = utf_encoded(data.to_s.dup) if config.prefix_data_lines diff --git a/spec/http_log_spec.rb b/spec/http_log_spec.rb index 7d84920..181766c 100644 --- a/spec/http_log_spec.rb +++ b/spec/http_log_spec.rb @@ -7,7 +7,7 @@ let(:host) { 'localhost' } let(:port) { 9292 } let(:path) { "/index.html" } - let(:headers) { { "accept" => "*/*", "foo" => "bar" } } + let(:headers) { { "accept" => "*/*", "foo" => "bar", 'Content-Type' => 'application/x-www-form-urlencoded' } } let(:data) { "foo=bar&bar=foo" } let(:params) { {'foo' => 'bar:form-data', 'bar' => 'foo'} }