faraday-gzip 3.0.0 → 3.0.2
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/CHANGELOG.md +4 -0
- data/lib/faraday/gzip/version.rb +1 -1
- metadata +3 -9
- data/spec/faraday/gzip/middleware_spec.rb +0 -179
- data/spec/faraday/gzip/version_spec.rb +0 -7
- data/spec/spec_helper.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45d5422fd045656fc52c28af8bb61860c73290f2b7882cb72a47136b5a837b10
|
4
|
+
data.tar.gz: 79e16aa5064e33c5f54459e14f0cb6c8f35b808344b374703bc6a628c9cd5652
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e2dbcd91159e307205222561cf2070b1ba8070e057a8ab846d9d03c093886c13103f86e79104dc2c76cf9566fe6a6610cf076504d76c1776de4499b1c6eb9c4
|
7
|
+
data.tar.gz: 924a0d4a6c4a76188d8f2bc9890ae12c4a185d3bb0b86495de457ee8109ffc1e95e99e43dcfccd969cf86f7f6c1668103d4efad5c9158d7b46d1e94870c3e5c8
|
data/CHANGELOG.md
CHANGED
data/lib/faraday/gzip/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday-gzip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ilya Krukowski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -172,16 +172,13 @@ files:
|
|
172
172
|
- lib/faraday/gzip.rb
|
173
173
|
- lib/faraday/gzip/middleware.rb
|
174
174
|
- lib/faraday/gzip/version.rb
|
175
|
-
- spec/faraday/gzip/middleware_spec.rb
|
176
|
-
- spec/faraday/gzip/version_spec.rb
|
177
|
-
- spec/spec_helper.rb
|
178
175
|
homepage: https://github.com/bodrovis/faraday-gzip
|
179
176
|
licenses:
|
180
177
|
- MIT
|
181
178
|
metadata:
|
182
179
|
bug_tracker_uri: https://github.com/bodrovis/faraday-gzip/issues
|
183
180
|
changelog_uri: https://github.com/bodrovis/faraday-gzip/blob/master/CHANGELOG.md
|
184
|
-
documentation_uri: http://www.rubydoc.info/gems/faraday-gzip/3.0.
|
181
|
+
documentation_uri: http://www.rubydoc.info/gems/faraday-gzip/3.0.2
|
185
182
|
homepage_uri: https://github.com/bodrovis/faraday-gzip
|
186
183
|
source_code_uri: https://github.com/bodrovis/faraday-gzip
|
187
184
|
rubygems_mfa_required: 'true'
|
@@ -194,9 +191,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
194
191
|
- - ">="
|
195
192
|
- !ruby/object:Gem::Version
|
196
193
|
version: '3.0'
|
197
|
-
- - "<"
|
198
|
-
- !ruby/object:Gem::Version
|
199
|
-
version: '4'
|
200
194
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
201
195
|
requirements:
|
202
196
|
- - ">="
|
@@ -1,179 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe Faraday::Gzip::Middleware do
|
4
|
-
require 'brotli' if Faraday::Gzip::Middleware::BROTLI_SUPPORTED
|
5
|
-
|
6
|
-
subject(:middleware) do
|
7
|
-
described_class.new(->(env) { Faraday::Response.new(env) })
|
8
|
-
end
|
9
|
-
|
10
|
-
let(:headers) { {} }
|
11
|
-
|
12
|
-
def process(body, content_type = nil, options = {})
|
13
|
-
env = {
|
14
|
-
body: body, request: options,
|
15
|
-
request_headers: Faraday::Utils::Headers.new,
|
16
|
-
response_headers: Faraday::Utils::Headers.new(headers)
|
17
|
-
}
|
18
|
-
env[:response_headers]['content-type'] = content_type if content_type
|
19
|
-
yield(env) if block_given?
|
20
|
-
middleware.call(env)
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'when request' do
|
24
|
-
it 'sets the Accept-Encoding request header' do
|
25
|
-
env = process('').env
|
26
|
-
encodings = Faraday::Gzip::Middleware::BROTLI_SUPPORTED ? 'gzip,deflate,br' : 'gzip,deflate'
|
27
|
-
expect(env[:request_headers][:accept_encoding]).to eq(encodings)
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'doesnt overwrite existing Accept-Encoding request header' do
|
31
|
-
env = process('') do |e|
|
32
|
-
e[:request_headers][:accept_encoding] = 'zopfli'
|
33
|
-
end.env
|
34
|
-
expect(env[:request_headers][:accept_encoding]).to eq('zopfli')
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
context 'when response' do
|
39
|
-
let(:uncompressed_body) do
|
40
|
-
'<html><head><title>Rspec</title></head><body>Hello, spec!</body></html>'
|
41
|
-
end
|
42
|
-
let(:empty_body) { '' }
|
43
|
-
let(:gzipped_body) do
|
44
|
-
io = StringIO.new
|
45
|
-
gz = Zlib::GzipWriter.new(io)
|
46
|
-
gz.write(uncompressed_body)
|
47
|
-
gz.close
|
48
|
-
res = io.string
|
49
|
-
res.force_encoding('BINARY')
|
50
|
-
res
|
51
|
-
end
|
52
|
-
let(:deflated_body) do
|
53
|
-
Zlib::Deflate.deflate(uncompressed_body)
|
54
|
-
end
|
55
|
-
let(:raw_deflated_body) do
|
56
|
-
z = Zlib::Deflate.new(Zlib::DEFAULT_COMPRESSION, -Zlib::MAX_WBITS)
|
57
|
-
compressed_body = z.deflate(uncompressed_body, Zlib::FINISH)
|
58
|
-
z.close
|
59
|
-
compressed_body
|
60
|
-
end
|
61
|
-
|
62
|
-
if Faraday::Gzip::Middleware::BROTLI_SUPPORTED
|
63
|
-
let(:brotlied_body) do
|
64
|
-
Brotli.deflate(uncompressed_body)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
shared_examples 'compressed response' do
|
69
|
-
it 'uncompresses the body' do
|
70
|
-
expect(process(body).body).to eq(uncompressed_body)
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'sets the Content-Length' do
|
74
|
-
expect(process(body).headers['Content-Length']).to eq(uncompressed_body.length)
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'removes the Content-Encoding' do
|
78
|
-
expect(process(body).headers['Content-Encoding']).to be_nil
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
context 'when gzipped response' do
|
83
|
-
let(:body) { gzipped_body }
|
84
|
-
let(:headers) { { 'Content-Encoding' => 'gzip', 'Content-Length' => body.length } }
|
85
|
-
|
86
|
-
it_behaves_like 'compressed response'
|
87
|
-
end
|
88
|
-
|
89
|
-
context 'when deflated response' do
|
90
|
-
let(:body) { deflated_body }
|
91
|
-
let(:headers) { { 'Content-Encoding' => 'deflate', 'Content-Length' => body.length } }
|
92
|
-
|
93
|
-
it_behaves_like 'compressed response'
|
94
|
-
end
|
95
|
-
|
96
|
-
context 'when raw deflated response' do
|
97
|
-
let(:body) { raw_deflated_body }
|
98
|
-
let(:headers) { { 'Content-Encoding' => 'deflate', 'Content-Length' => body.length } }
|
99
|
-
|
100
|
-
it_behaves_like 'compressed response'
|
101
|
-
end
|
102
|
-
|
103
|
-
if Faraday::Gzip::Middleware::BROTLI_SUPPORTED
|
104
|
-
context 'when brotlied response' do
|
105
|
-
let(:body) { brotlied_body }
|
106
|
-
let(:headers) { { 'Content-Encoding' => 'br', 'Content-Length' => body.length } }
|
107
|
-
|
108
|
-
it_behaves_like 'compressed response'
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
context 'when empty response' do
|
113
|
-
let(:body) { empty_body }
|
114
|
-
let(:headers) { { 'Content-Encoding' => 'gzip', 'Content-Length' => body.length } }
|
115
|
-
|
116
|
-
it 'sets the Content-Length' do
|
117
|
-
expect(process(body).headers['Content-Length']).to eq(empty_body.length)
|
118
|
-
end
|
119
|
-
|
120
|
-
it 'removes the Content-Encoding' do
|
121
|
-
expect(process(body).headers['Content-Encoding']).to be_nil
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
context 'when nil response' do
|
126
|
-
let(:body) { nil }
|
127
|
-
let(:headers) { { 'Content-Encoding' => 'gzip', 'Content-Length' => 0 } }
|
128
|
-
|
129
|
-
it 'sets the Content-Length' do
|
130
|
-
expect(process(body).headers['Content-Length']).to eq(0)
|
131
|
-
end
|
132
|
-
|
133
|
-
it 'removes the Content-Encoding' do
|
134
|
-
expect(process(body).headers['Content-Encoding']).to be_nil
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
context 'when identity response' do
|
139
|
-
let(:body) { uncompressed_body }
|
140
|
-
|
141
|
-
it 'does not modify the body' do
|
142
|
-
expect(process(body).body).to eq(uncompressed_body)
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
context 'when unsupported encoding response' do
|
147
|
-
let(:body) { 'unsupported' }
|
148
|
-
let(:headers) { { 'Content-Encoding' => 'unsupported' } }
|
149
|
-
|
150
|
-
it 'does not modify the body' do
|
151
|
-
expect(process(body).body).to eq(body)
|
152
|
-
end
|
153
|
-
|
154
|
-
it 'preserves the Content-Encoding header' do
|
155
|
-
expect(process(body).headers['Content-Encoding']).to eq('unsupported')
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
context 'when no Content-Encoding header' do
|
160
|
-
let(:body) { uncompressed_body }
|
161
|
-
let(:headers) { {} }
|
162
|
-
|
163
|
-
it 'does not modify the body' do
|
164
|
-
expect(process(body).body).to eq(uncompressed_body)
|
165
|
-
end
|
166
|
-
|
167
|
-
it 'does not add a Content-Encoding header' do
|
168
|
-
expect(process(body).headers['Content-Encoding']).to be_nil
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
context 'when Content-Length is a string' do
|
173
|
-
let(:body) { gzipped_body }
|
174
|
-
let(:headers) { { 'Content-Encoding' => 'gzip', 'Content-Length' => body.length.to_s } }
|
175
|
-
|
176
|
-
it_behaves_like 'compressed response'
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'faraday'
|
4
|
-
require 'simplecov'
|
5
|
-
|
6
|
-
SimpleCov.start do
|
7
|
-
add_filter 'spec/'
|
8
|
-
add_filter '.github/'
|
9
|
-
end
|
10
|
-
|
11
|
-
require_relative '../lib/faraday/gzip'
|
12
|
-
|
13
|
-
RSpec.configure do |config|
|
14
|
-
# Enable flags like --only-failures and --next-failure
|
15
|
-
config.example_status_persistence_file_path = '.rspec_status'
|
16
|
-
|
17
|
-
# Disable RSpec exposing methods globally on `Module` and `main`
|
18
|
-
config.disable_monkey_patching!
|
19
|
-
|
20
|
-
config.expect_with :rspec do |c|
|
21
|
-
c.syntax = :expect
|
22
|
-
end
|
23
|
-
|
24
|
-
config.order = :random
|
25
|
-
end
|