akita-har_logger 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/lib/akita/har_logger/har_utils.rb +12 -2
- data/lib/akita/har_logger/http_request.rb +27 -5
- data/lib/akita/har_logger/http_response.rb +3 -1
- data/lib/akita/har_logger/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a4d073bcb2347b0527e3dab531c77770a29c29326bf76cb2ca09724206af8e5
|
4
|
+
data.tar.gz: 2fc8b6e0b4721699f87a08ba098b3d6137835b14c01eeb73b945a453a98267f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f07983494e000f9ed64ffdfe346869bdd0b574db21210a39de0199d1df81f877262c2623c72ca918c792cff77a29872224a5ba3d5f3ac12691381d8caf89bc17
|
7
|
+
data.tar.gz: 513be52cfaf7f114cb95ed33df45528336db9f9945ac5252db12a9abfe30103308cd1d7d92585ec6ac8897c231129e0d83cee596a3df3034946c88b5c59dcde6
|
data/Gemfile.lock
CHANGED
@@ -3,14 +3,24 @@
|
|
3
3
|
module Akita
|
4
4
|
module HarLogger
|
5
5
|
class HarUtils
|
6
|
+
# Rack apparently uses 8-bit ASCII for everything, even when the string
|
7
|
+
# is not 8-bit ASCII. This reinterprets the given string as UTF-8.
|
8
|
+
def self.fixEncoding(v)
|
9
|
+
if v == nil || v.encoding == Encoding::UTF_8 then
|
10
|
+
v
|
11
|
+
else
|
12
|
+
String.new(v).force_encoding(Encoding::UTF_8)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
6
16
|
# Converts a Hash into a list of Hash objects. Each entry in the given
|
7
17
|
# Hash will be represented in the output by a Hash object that maps
|
8
18
|
# 'name' to the entry's key and 'value' to the entry's value.
|
9
19
|
def self.hashToList(hash)
|
10
20
|
hash.reduce([]) { |accum, (k, v)|
|
11
21
|
accum.append({
|
12
|
-
name: k,
|
13
|
-
value: v,
|
22
|
+
name: fixEncoding(k),
|
23
|
+
value: fixEncoding(v),
|
14
24
|
})
|
15
25
|
}
|
16
26
|
end
|
@@ -11,7 +11,7 @@ module Akita
|
|
11
11
|
|
12
12
|
@self = {
|
13
13
|
method: getMethod(env),
|
14
|
-
url: req.url,
|
14
|
+
url: HarUtils.fixEncoding(req.url),
|
15
15
|
httpVersion: getHttpVersion(env),
|
16
16
|
cookies: getCookies(env),
|
17
17
|
headers: getHeaders(env),
|
@@ -33,7 +33,7 @@ module Akita
|
|
33
33
|
|
34
34
|
# Obtains the client's request method from an HTTP environment.
|
35
35
|
def getMethod(env)
|
36
|
-
(Rack::Request.new env).request_method
|
36
|
+
HarUtils.fixEncoding (Rack::Request.new env).request_method
|
37
37
|
end
|
38
38
|
|
39
39
|
# Obtains the client-requested HTTP version from an HTTP environment.
|
@@ -41,7 +41,9 @@ module Akita
|
|
41
41
|
# The environment doesn't have HTTP_VERSION when running with `rspec`;
|
42
42
|
# assume HTTP/1.1 when this happens. We don't return nil, so we can
|
43
43
|
# calculate the size of the headers.
|
44
|
-
env.key?('HTTP_VERSION') ?
|
44
|
+
env.key?('HTTP_VERSION') ?
|
45
|
+
HarUtils.fixEncoding(env['HTTP_VERSION']) :
|
46
|
+
'HTTP/1.1'
|
45
47
|
end
|
46
48
|
|
47
49
|
# Builds a list of cookie objects from an HTTP environment.
|
@@ -71,13 +73,28 @@ module Akita
|
|
71
73
|
HarUtils.hashToList paramMap
|
72
74
|
end
|
73
75
|
|
76
|
+
# Obtains the character set of the posted data from an HTTP environment.
|
77
|
+
def getPostDataCharSet(env)
|
78
|
+
req = Rack::Request.new env
|
79
|
+
if req.content_charset != nil then
|
80
|
+
return req.content_charset
|
81
|
+
end
|
82
|
+
|
83
|
+
# RFC 2616 says that "text/*" defaults to ISO-8859-1.
|
84
|
+
if env['CONTENT_TYPE'].start_with?('text/') then
|
85
|
+
return Encoding::ISO_8859_1
|
86
|
+
end
|
87
|
+
|
88
|
+
Encoding.default_external
|
89
|
+
end
|
90
|
+
|
74
91
|
# Obtains the posted data from an HTTP environment.
|
75
92
|
def getPostData(env)
|
76
93
|
if env.key?('CONTENT_TYPE') && env['CONTENT_TYPE'] then
|
77
94
|
result = { mimeType: env['CONTENT_TYPE'] }
|
78
95
|
|
79
96
|
# Populate 'params' if we have URL-encoded parameters. Otherwise,
|
80
|
-
# populate 'text.
|
97
|
+
# populate 'text'.
|
81
98
|
req = Rack::Request.new env
|
82
99
|
if env['CONTENT_TYPE'] == 'application/x-www-form-urlencoded' then
|
83
100
|
# Decoded parameters can be found as a map in req.params.
|
@@ -96,7 +113,12 @@ module Akita
|
|
96
113
|
result[:text] = req.params.to_json
|
97
114
|
end
|
98
115
|
else
|
99
|
-
|
116
|
+
# Rack has been observed to use ASCII-8BIT encoding for the request
|
117
|
+
# body when the request specifies UTF-8. Reinterpret the content
|
118
|
+
# body according to what the request says it is, and re-encode into
|
119
|
+
# UTF-8.
|
120
|
+
result[:text] = req.body.string.encode(Encoding::UTF_8,
|
121
|
+
getPostDataCharSet(env))
|
100
122
|
end
|
101
123
|
|
102
124
|
result
|
@@ -36,7 +36,9 @@ module Akita
|
|
36
36
|
# The environment doesn't have HTTP_VERSION when running with `rspec`;
|
37
37
|
# assume HTTP/1.1 when this happens. We don't return nil, so we can
|
38
38
|
# calculate the size of the headers.
|
39
|
-
env.key?('HTTP_VERSION') ?
|
39
|
+
env.key?('HTTP_VERSION') ?
|
40
|
+
HarUtils.fixEncoding(env['HTTP_VERSION']) :
|
41
|
+
'HTTP/1.1'
|
40
42
|
end
|
41
43
|
|
42
44
|
def getCookies(headers)
|
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.3
|
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-
|
11
|
+
date: 2021-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -69,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
69
|
- !ruby/object:Gem::Version
|
70
70
|
version: '0'
|
71
71
|
requirements: []
|
72
|
-
rubygems_version: 3.2.
|
72
|
+
rubygems_version: 3.2.21
|
73
73
|
signing_key:
|
74
74
|
specification_version: 4
|
75
75
|
summary: Rails middleware for HAR logging
|