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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/akita/har_logger.rb +35 -0
- data/lib/akita/har_logger/har_utils.rb +1 -1
- data/lib/akita/har_logger/http_request.rb +3 -2
- data/lib/akita/har_logger/http_response.rb +3 -1
- data/lib/akita/har_logger/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95fc4c3e51ec19663e862655884702fdcc42aa567f0ca706f1b2dfda065662e5
|
4
|
+
data.tar.gz: 04c93b6cc55669bec6b303803928d1c28bd44aa770a7f4b88763cb430f7f7d90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f76e965199fff57f90f321c3293b6c8447ac1fbfec7d5987ef5bc7e005aa98527d34c33d79f92ff964267b086208d121ad0d25774a19c00f2dbea9455eaf40ab
|
7
|
+
data.tar.gz: 287cc1c7f0eb46932b224764171f26612e406afc2d388ee30d5c238000349161741c14afb9def65af27d2703c5ac1c908763241e07e35f269ae1b064a6b8d922
|
data/Gemfile.lock
CHANGED
data/lib/akita/har_logger.rb
CHANGED
@@ -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
|
|
@@ -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
|
-
|
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].
|
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
|
-
|
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
|
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.
|
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-
|
11
|
+
date: 2021-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|