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

Fix request data logging for httprb/http version 4 #56

Merged
merged 2 commits into from
Feb 18, 2018
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
pkg/
*.gem
coverage/
spec/log/*.log
spec/log/*.log
gemfiles/*.lock
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions gemfiles/http2.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source "https://rubygems.org"

gem "http", "~> 2.0"

gemspec path: ".."
5 changes: 5 additions & 0 deletions gemfiles/http3.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source "https://rubygems.org"

gem "http", "~> 3.0"

gemspec path: ".."
5 changes: 5 additions & 0 deletions gemfiles/http4.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source "https://rubygems.org"

gem "http", github: "httprb/http"

gemspec path: ".."
10 changes: 9 additions & 1 deletion lib/httplog/adapters/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down