akita-har_logger 0.2.4 → 0.2.5
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/har_utils.rb +12 -4
- data/lib/akita/har_logger/http_request.rb +22 -3
- 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: d1a952e08b6244134dc4498e24b7185a700fe6d60abdc257bae8e5c3f67a57c6
|
4
|
+
data.tar.gz: 205780425d013375017a8677630c68c078b3be55772ebc0bebf0968d8e16601b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0beadf21aa88256c40d0b6bc4c2e0c54dae7656aea1cd472b8ae7a610484969f70ed9239c3a783362eaf68be41c373085cb181eb456bce413510e8f50d5a50ed
|
7
|
+
data.tar.gz: 622997ac27c899f809b1d7c632ca0da6f8916f00a25b9cdb22d8d6861b1107c8226cfd7802c9b03745d774268780d066db5bcb739081a06c66cd89cee235016a
|
data/Gemfile.lock
CHANGED
@@ -5,12 +5,20 @@ module Akita
|
|
5
5
|
class HarUtils
|
6
6
|
# Rack apparently uses 8-bit ASCII for everything, even when the string
|
7
7
|
# is not 8-bit ASCII. This reinterprets 8-bit ASCII strings as UTF-8.
|
8
|
+
#
|
9
|
+
# If we are unable to do this reinterpretation, return the string
|
10
|
+
# unchanged, but log a warning that points to the caller.
|
8
11
|
def self.fixEncoding(v)
|
9
|
-
if v
|
10
|
-
v
|
11
|
-
|
12
|
-
|
12
|
+
if v != nil && v.encoding == Encoding::ASCII_8BIT then
|
13
|
+
forced = String.new(v).force_encoding(Encoding::UTF_8)
|
14
|
+
if forced.valid_encoding? then
|
15
|
+
v = forced
|
16
|
+
else
|
17
|
+
Rails.logger.warn "[#{caller_locations(1, 1)}] Unable to fix encoding: not a valid UTF-8 string. This will likely cause JSON serialization to fail."
|
18
|
+
end
|
13
19
|
end
|
20
|
+
|
21
|
+
v
|
14
22
|
end
|
15
23
|
|
16
24
|
# Converts a Hash into a list of Hash objects. Each entry in the given
|
@@ -85,7 +85,7 @@ module Akita
|
|
85
85
|
return Encoding::ISO_8859_1
|
86
86
|
end
|
87
87
|
|
88
|
-
Encoding
|
88
|
+
Encoding::ASCII_8BIT
|
89
89
|
end
|
90
90
|
|
91
91
|
# Obtains the posted data from an HTTP environment.
|
@@ -117,8 +117,27 @@ module Akita
|
|
117
117
|
# body when the request specifies UTF-8. Reinterpret the content
|
118
118
|
# body according to what the request says it is, and re-encode into
|
119
119
|
# UTF-8.
|
120
|
-
|
121
|
-
|
120
|
+
#
|
121
|
+
# Gracefully handle any characters that are invalid in the source
|
122
|
+
# encoding and characters that have no UTF-8 representation by
|
123
|
+
# replacing with '?'. Log a warning when this happens.
|
124
|
+
source = req.body.string.force_encoding(getPostDataCharSet(env))
|
125
|
+
utf8EncodingSuccessful = false
|
126
|
+
if source.valid_encoding? then
|
127
|
+
begin
|
128
|
+
result[:text] = source.encode(Encoding::UTF_8)
|
129
|
+
utf8EncodingSuccessful = true
|
130
|
+
rescue Encoding::UndefinedConversionError
|
131
|
+
Rails.logger.warn "[#{caller_locations(0, 1)}] Unable to losslessly convert request body from #{source.encoding} to UTF-8. Characters undefined in UTF-8 will be replaced with '?'."
|
132
|
+
end
|
133
|
+
else
|
134
|
+
Rails.logger.warn "[#{caller_locations(0, 1)}] Request body is not valid #{source.encoding}. Invalid characters and characters undefined in UTF-8 will be replaced with '?'."
|
135
|
+
end
|
136
|
+
|
137
|
+
if !utf8EncodingSuccessful then
|
138
|
+
result[:text] = source.encode(Encoding::UTF_8,
|
139
|
+
invalid: :replace, undef: :replace, replace: '?')
|
140
|
+
end
|
122
141
|
end
|
123
142
|
|
124
143
|
result
|
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.5
|
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-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|