diff --git a/.gitignore b/.gitignore index 63e0d84..ab15e3f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ pkg/ *.gem coverage/ -spec/log/*.log \ No newline at end of file +spec/log/*.log +gemfiles/*.lock diff --git a/.travis.yml b/.travis.yml index 37d25b9..8d0c4b0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,10 @@ rvm: - "2.2.8" - "2.3.5" - "2.4.2" +gemfile: + - gemfiles/http2.gemfile + - gemfiles/http3.gemfile + - gemfiles/http4.gemfile # uncomment this line if your project needs to run something other than `rake`: script: bundle exec rspec spec # workaround for https://github.com/travis-ci/travis-ci/issues/5239: diff --git a/gemfiles/http2.gemfile b/gemfiles/http2.gemfile new file mode 100644 index 0000000..fcf14ad --- /dev/null +++ b/gemfiles/http2.gemfile @@ -0,0 +1,5 @@ +source "https://rubygems.org" + +gem "http", "~> 2.0" + +gemspec path: ".." diff --git a/gemfiles/http3.gemfile b/gemfiles/http3.gemfile new file mode 100644 index 0000000..e6b7732 --- /dev/null +++ b/gemfiles/http3.gemfile @@ -0,0 +1,5 @@ +source "https://rubygems.org" + +gem "http", "~> 3.0" + +gemspec path: ".." diff --git a/gemfiles/http4.gemfile b/gemfiles/http4.gemfile new file mode 100644 index 0000000..db34094 --- /dev/null +++ b/gemfiles/http4.gemfile @@ -0,0 +1,5 @@ +source "https://rubygems.org" + +gem "http", github: "httprb/http" + +gemspec path: ".." diff --git a/lib/httplog/adapters/http.rb b/lib/httplog/adapters/http.rb index 9b1f6ea..ce8e3d0 100644 --- a/lib/httplog/adapters/http.rb +++ b/lib/httplog/adapters/http.rb @@ -14,7 +14,15 @@ 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 + + if defined?(::HTTP::Request::Body) + body = req.body.respond_to?(:source) ? req.body.source : req.body.instance_variable_get(:@body) + else + body = req.body + end + + HttpLog.log_data(body.to_s) + body.rewind if body.respond_to?(:rewind) end bm = Benchmark.realtime do