httplog 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -8,7 +8,7 @@ So far this gem works with the following ruby modules and libraries:
8
8
 
9
9
  * [Net::HTTP](http://www.ruby-doc.org/stdlib-1.9.3/libdoc/net/http/rdoc/index.html)
10
10
  * [Ethon](https://github.com/typhoeus/ethon)
11
- * [Excon](https://github.com/geemus/excon)
11
+ * [Excon](https://github.com/geemus/excon) (for excon >= v18.0, httplog >= 0.2.4 is required)
12
12
  * [OpenURI](http://www.ruby-doc.org/stdlib-1.9.3/libdoc/open-uri/rdoc/index.html)
13
13
  * [Patron](https://github.com/toland/patron)
14
14
  * [HTTPClient](https://github.com/nahi/httpclient)
@@ -3,8 +3,8 @@ if defined?(Excon)
3
3
  class Socket
4
4
  alias_method :orig_connect, :connect
5
5
  def connect
6
- host = @proxy ? @proxy[:host] : @params[:host]
7
- port = @proxy ? @proxy[:port] : @params[:port]
6
+ host = @data[:proxy] ? @data[:proxy][:host] : @data[:host]
7
+ port = @data[:proxy] ? @data[:proxy][:port] : @data[:port]
8
8
  HttpLog.log_connection(host, port)
9
9
  orig_connect
10
10
  end
@@ -12,24 +12,39 @@ if defined?(Excon)
12
12
  end
13
13
 
14
14
  class Connection
15
- alias_method :orig_request_kernel, :request_kernel
16
- def request_kernel(params)
17
- url = "#{params[:scheme]}://#{params[:host]}:#{params[:port]}#{params[:path]}#{params[:query]}"
18
- HttpLog.log_request(params[:method], url)
19
- HttpLog.log_headers(params[:headers])
20
- HttpLog.log_data(params[:body]) if params[:method] == :post
21
15
 
22
- response = nil
16
+ def _httplog_url(datum)
17
+ "#{datum[:scheme]}://#{datum[:host]}:#{datum[:port]}#{datum[:path]}#{datum[:query]}"
18
+ end
19
+
20
+ alias_method :orig_request, :request
21
+ def request(params, &block)
22
+ datum = nil
23
23
  bm = Benchmark.realtime do
24
- response = orig_request_kernel(params)
24
+ datum = orig_request(params, &block)
25
25
  end
26
-
27
- HttpLog.log_compact(params[:method], url, response.status, bm)
28
- HttpLog.log_status(response.status)
26
+ HttpLog.log_compact(datum[:method], _httplog_url(datum), datum[:status], bm)
29
27
  HttpLog.log_benchmark(bm)
30
- HttpLog.log_body(response.body)
28
+ datum
29
+ end
31
30
 
32
- response
31
+ alias_method :orig_request_call, :request_call
32
+ def request_call(datum)
33
+ HttpLog.log_request(datum[:method], _httplog_url(datum))
34
+ HttpLog.log_headers(datum[:headers])
35
+ HttpLog.log_data(datum[:body]) if datum[:method] == :post
36
+ orig_request_call(datum)
37
+ end
38
+
39
+ alias_method :orig_response, :response
40
+ def response(datum={})
41
+ bm = Benchmark.realtime do
42
+ datum = orig_response(datum)
43
+ end
44
+ response = datum[:response]
45
+ HttpLog.log_status(response[:status])
46
+ HttpLog.log_body(response[:body])
47
+ datum
33
48
  end
34
49
  end
35
50
  end
@@ -23,7 +23,8 @@ module Net
23
23
  HttpLog.log_compact(req.method, url, @response.code, bm)
24
24
  HttpLog.log_status(@response.code)
25
25
  HttpLog.log_benchmark(bm)
26
- HttpLog.log_body(@response.body)
26
+ HttpLog.log_headers(@response.each_header.collect)
27
+ HttpLog.log_body(@response.body, @response.header["Content-Encoding"])
27
28
  end
28
29
 
29
30
  @response
@@ -57,14 +57,20 @@ module HttpLog
57
57
  log("Benchmark: #{seconds} seconds")
58
58
  end
59
59
 
60
- def log_body(body)
60
+ def log_body(body, encoding = nil)
61
61
  return if options[:compact_log] || !options[:log_response]
62
62
  if body.is_a?(Net::ReadAdapter)
63
63
  # open-uri wraps the response in a Net::ReadAdapter that defers reading
64
64
  # the content, so the reponse body is not available here.
65
65
  log("Response: (not available yet)")
66
66
  else
67
- log("Response:\n#{body.to_s}")
67
+ if encoding =~ /gzip/
68
+ sio = StringIO.new( body.to_s )
69
+ gz = Zlib::GzipReader.new( sio )
70
+ log("Response: (deflated)\n#{gz.read}")
71
+ else
72
+ log("Response:\n#{body.to_s}")
73
+ end
68
74
  end
69
75
  end
70
76
 
@@ -1,4 +1,4 @@
1
1
  module HttpLog
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httplog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-04 00:00:00.000000000 Z
12
+ date: 2013-03-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -114,7 +114,7 @@ dependencies:
114
114
  requirements:
115
115
  - - ! '>='
116
116
  - !ruby/object:Gem::Version
117
- version: '0'
117
+ version: 0.18.0
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
@@ -122,7 +122,7 @@ dependencies:
122
122
  requirements:
123
123
  - - ! '>='
124
124
  - !ruby/object:Gem::Version
125
- version: '0'
125
+ version: 0.18.0
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: typhoeus
128
128
  requirement: !ruby/object:Gem::Requirement
@@ -202,18 +202,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
202
202
  - - ! '>='
203
203
  - !ruby/object:Gem::Version
204
204
  version: '0'
205
- segments:
206
- - 0
207
- hash: 1928624489278995380
208
205
  required_rubygems_version: !ruby/object:Gem::Requirement
209
206
  none: false
210
207
  requirements:
211
208
  - - ! '>='
212
209
  - !ruby/object:Gem::Version
213
210
  version: '0'
214
- segments:
215
- - 0
216
- hash: 1928624489278995380
217
211
  requirements: []
218
212
  rubyforge_project:
219
213
  rubygems_version: 1.8.24
@@ -221,3 +215,4 @@ signing_key:
221
215
  specification_version: 3
222
216
  summary: Logs outgoing HTTP requests.
223
217
  test_files: []
218
+ has_rdoc: