From b34099133b482c250c0b5bbb5f5a2a2de4087b43 Mon Sep 17 00:00:00 2001 From: Yuri Smirnov Date: Wed, 14 Feb 2018 13:15:51 +0300 Subject: [PATCH 1/2] fix for httprb/http version 4 --- lib/httplog/adapters/http.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/httplog/adapters/http.rb b/lib/httplog/adapters/http.rb index 9b1f6ea..05d2be9 100644 --- a/lib/httplog/adapters/http.rb +++ b/lib/httplog/adapters/http.rb @@ -14,7 +14,10 @@ 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 + body = req.body + body = body.source if body.respond_to?(:source) + HttpLog.log_data(body.to_s) + body.rewind if body.respond_to?(:rewind) end bm = Benchmark.realtime do From d421580a4d56baa63c7d9a880d381258d300b2a2 Mon Sep 17 00:00:00 2001 From: Yuri Smirnov Date: Wed, 14 Feb 2018 16:48:41 +0300 Subject: [PATCH 2/2] support HTTP version 3 + update travis config --- .gitignore | 3 ++- .travis.yml | 4 ++++ gemfiles/http2.gemfile | 5 +++++ gemfiles/http3.gemfile | 5 +++++ gemfiles/http4.gemfile | 5 +++++ lib/httplog/adapters/http.rb | 9 +++++++-- 6 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 gemfiles/http2.gemfile create mode 100644 gemfiles/http3.gemfile create mode 100644 gemfiles/http4.gemfile 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 05d2be9..ce8e3d0 100644 --- a/lib/httplog/adapters/http.rb +++ b/lib/httplog/adapters/http.rb @@ -14,8 +14,13 @@ class Client if log_enabled HttpLog.log_request(req.verb, req.uri) HttpLog.log_headers(req.headers.to_h) - body = req.body - body = body.source if body.respond_to?(:source) + + 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