akita-har_logger 0.2.7 → 0.2.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2030633ff794a611ceb1fddba8b274e5617765c0644dcdebbe6743515dd0576
4
- data.tar.gz: c3b1eb76987d0db9dcf63830a67882cbdfbaceeba937c1a9a20a874ddc4efd42
3
+ metadata.gz: 95fc4c3e51ec19663e862655884702fdcc42aa567f0ca706f1b2dfda065662e5
4
+ data.tar.gz: 04c93b6cc55669bec6b303803928d1c28bd44aa770a7f4b88763cb430f7f7d90
5
5
  SHA512:
6
- metadata.gz: 7b7e2cbf0e7580c044ca178d58af63fc41059318475f033314bf9fbba9ce3546da02808b2c237c6cef6ada40d6b6eebaf905ed2201f943367deea8fc49342d5b
7
- data.tar.gz: c8637bc4282a1571b0366e1dbff4948771a7d10913b26c7df595996b4096dcd18e8119448cf3f578c9d33f3acf12034c05d92b62ce1900eff34b4c5adb71fe9f
6
+ metadata.gz: f76e965199fff57f90f321c3293b6c8447ac1fbfec7d5987ef5bc7e005aa98527d34c33d79f92ff964267b086208d121ad0d25774a19c00f2dbea9455eaf40ab
7
+ data.tar.gz: 287cc1c7f0eb46932b224764171f26612e406afc2d388ee30d5c238000349161741c14afb9def65af27d2703c5ac1c908763241e07e35f269ae1b064a6b8d922
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- akita-har_logger (0.2.7)
4
+ akita-har_logger (0.2.11)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -37,18 +37,41 @@ module Akita
37
37
 
38
38
  def call(env)
39
39
  start_time = Time.now
40
+
41
+ # Read the request body here, in case there is non-Rack-compliant
42
+ # middleware in the stack that closes the request-body stream on us.
43
+ request_body = env['rack.input'].read
44
+ env['rack.input'].rewind # Be kind.
45
+
40
46
  status, headers, body = @app.call(env)
41
47
  end_time = Time.now
42
48
 
43
49
  wait_time_ms = ((end_time.to_f - start_time.to_f) * 1000).round
44
50
 
51
+ # Patch env with our saved request body.
52
+ saved_input = env['rack.input']
53
+ env['rack.input'] = StringIO.new request_body
54
+
55
+ # Buffer the response body in case it's not a rewindable stream.
56
+ body = HarLogger.bufferBody(body)
57
+
45
58
  @entry_queue << (HarEntry.new start_time, wait_time_ms, env, status,
46
59
  headers, body)
47
60
 
61
+ # Be kind and restore the original request-body stream.
62
+ env['rack.input'] = saved_input
63
+
48
64
  [ status, headers, body ]
49
65
  end
50
66
  end
51
67
 
68
+ # Reads the given body into an array and returns the result.
69
+ def self.bufferBody(body)
70
+ result = []
71
+ body.each { |part| result << part }
72
+ result
73
+ end
74
+
52
75
  # Logging filter for `ActionController`s.
53
76
  # TODO: Some amount of code duplication here. Should refactor.
54
77
  class Filter
@@ -72,6 +95,11 @@ module Akita
72
95
  def around(controller)
73
96
  start_time = Time.now
74
97
 
98
+ # Read the request body here, in case there is non-Rack-compliant
99
+ # middleware in the stack that closes the request-body stream on us.
100
+ request_body = controller.response.request.env['rack.input'].read
101
+ controller.response.request.env['rack.input'].rewind # Be kind.
102
+
75
103
  yield
76
104
 
77
105
  end_time = Time.now
@@ -80,9 +108,16 @@ module Akita
80
108
  response = controller.response
81
109
  request = response.request
82
110
 
111
+ # Patch env with our saved request body.
112
+ saved_input = request.env['rack.input']
113
+ request.env['rack.input'] = StringIO.new request_body
114
+
83
115
  @entry_queue << (HarEntry.new start_time, wait_time_ms, request.env,
84
116
  response.status, response.headers,
85
117
  [response.body])
118
+
119
+ # Be kind and restore the original request-body stream.
120
+ request.env['rack.input'] = saved_input
86
121
  end
87
122
  end
88
123
 
@@ -39,7 +39,7 @@ module Akita
39
39
  hash.reduce([]) { |accum, (k, v)|
40
40
  accum.append({
41
41
  name: fixEncoding(k),
42
- value: fixEncoding(v),
42
+ value: fixEncoding(v.to_s),
43
43
  })
44
44
  }
45
45
  end
@@ -121,7 +121,8 @@ module Akita
121
121
  # Gracefully handle any characters that are invalid in the source
122
122
  # encoding and characters that have no UTF-8 representation by
123
123
  # replacing with '?'. Log a warning when this happens.
124
- source = req.body.string.force_encoding(getPostDataCharSet(env))
124
+ sourceCharset = getPostDataCharSet(env)
125
+ source = String.new(req.body.read).force_encoding(sourceCharset)
125
126
  utf8EncodingSuccessful = false
126
127
  if source.valid_encoding? then
127
128
  begin
@@ -163,7 +164,7 @@ module Akita
163
164
  # for the CRLF on the blank line.
164
165
  getHeaders(env).reduce(line_length + 2) { |accum, entry|
165
166
  # Header-Name: header value<CR><LF>
166
- accum + entry[:name].length + 2 + entry[:value].to_s.length + 2
167
+ accum + entry[:name].length + 2 + entry[:value].length + 2
167
168
  }
168
169
  end
169
170
 
@@ -159,7 +159,9 @@ module Akita
159
159
 
160
160
  def getBodySize(body)
161
161
  length = 0
162
- body.each { |part| length += part.bytesize }
162
+ # Convert each body part into a string in case we're dealing with
163
+ # non-Rack-compliant components.
164
+ body.each { |part| length += part.to_s.bytesize }
163
165
  length
164
166
  end
165
167
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Akita
4
4
  module HarLogger
5
- VERSION = "0.2.7"
5
+ VERSION = "0.2.11"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: akita-har_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jed Liu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-15 00:00:00.000000000 Z
11
+ date: 2021-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec