faraday-gzip 3.0.1 → 3.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5a6ceb06f7b18d8d70a15a0a8ceda7cf7a2956df6653066f8ae0c84c0f1c832a
4
- data.tar.gz: 9cde727357feea0a7efe5fe80a73c95942eb5fbcd0b21fa7a20c54d92acb91e8
3
+ metadata.gz: 801efea11d6b5a0e1f2d82c802cb6e0eea73bf542f7b9a793ff2288cefcc6c7f
4
+ data.tar.gz: d6d5f77de67e0223cdbf225cdb52e121d548a7202bd91bc4acfd50b9b0ef7e25
5
5
  SHA512:
6
- metadata.gz: 5ee966bedad1ea9379de2f5f8c971326488366d831df22e78c7f29557a41189befce5bf0be373482de72b441a94e3d435db7812c980f69258cdb8ca207decd08
7
- data.tar.gz: '08f511d78ee79f136d2ba4d5770585ec4a146296e8d6b2c72bdf4efbba5e450fb8a84988872da4b7278c3bcd9b183b7c513e6e7880000052d33bed5bfd6dceac'
6
+ metadata.gz: 715ab8b38d3050eacbbe21ac8f7444390e31d4807bd9908c6671ced6511c36b849ab11ec806140f2730d131b39dd8b90f7e08d03f69c4b2851a0df366020a78a
7
+ data.tar.gz: dd479efd565f0b80e371ee7f5b1883614c52f7d55a78b8e5df92a80cb5a5d940e1f8049bc0dddff5d97a56e6935b554d106fa223700f35536d3dfc3b876effa4
data/CHANGELOG.md CHANGED
@@ -1,8 +1,12 @@
1
1
  # Changelog
2
2
 
3
- ## 3.0.1 (01-Nov-2024)
3
+ ## 3.0.3 (25-Feb-2025)
4
4
 
5
- * Minor fix in gemspec
5
+ * Minor code fixes, make some methods more solid
6
+
7
+ ## 3.0.1 / 3.0.2 (01-Nov-2024)
8
+
9
+ * Minor fixes in gemspec
6
10
 
7
11
  ## 3.0.0 (29-Oct-2024)
8
12
 
@@ -67,7 +67,11 @@ module Faraday
67
67
  def uncompress_gzip(body)
68
68
  io = StringIO.new(body)
69
69
  gzip_reader = Zlib::GzipReader.new(io, encoding: 'ASCII-8BIT')
70
- gzip_reader.read
70
+ begin
71
+ gzip_reader.read
72
+ ensure
73
+ gzip_reader.close
74
+ end
71
75
  end
72
76
 
73
77
  # Process deflate
@@ -103,7 +107,7 @@ module Faraday
103
107
 
104
108
  # Method providing the processors
105
109
  def processors
106
- {
110
+ @processors ||= {
107
111
  'gzip' => ->(body) { uncompress_gzip(body) },
108
112
  'deflate' => ->(body) { inflate(body) },
109
113
  'br' => ->(body) { brotli_inflate(body) }
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Faraday
4
4
  module Gzip
5
- VERSION = '3.0.1'
5
+ VERSION = '3.0.3'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faraday-gzip
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Krukowski
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-11-01 00:00:00.000000000 Z
10
+ date: 2025-02-25 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: faraday
@@ -114,20 +113,6 @@ dependencies:
114
113
  - - "~>"
115
114
  - !ruby/object:Gem::Version
116
115
  version: '1.32'
117
- - !ruby/object:Gem::Dependency
118
- name: rubocop-packaging
119
- requirement: !ruby/object:Gem::Requirement
120
- requirements:
121
- - - "~>"
122
- - !ruby/object:Gem::Version
123
- version: 0.5.0
124
- type: :development
125
- prerelease: false
126
- version_requirements: !ruby/object:Gem::Requirement
127
- requirements:
128
- - - "~>"
129
- - !ruby/object:Gem::Version
130
- version: 0.5.0
131
116
  - !ruby/object:Gem::Dependency
132
117
  name: rubocop-performance
133
118
  requirement: !ruby/object:Gem::Requirement
@@ -172,20 +157,15 @@ files:
172
157
  - lib/faraday/gzip.rb
173
158
  - lib/faraday/gzip/middleware.rb
174
159
  - 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
160
  homepage: https://github.com/bodrovis/faraday-gzip
179
161
  licenses:
180
162
  - MIT
181
163
  metadata:
182
164
  bug_tracker_uri: https://github.com/bodrovis/faraday-gzip/issues
183
165
  changelog_uri: https://github.com/bodrovis/faraday-gzip/blob/master/CHANGELOG.md
184
- documentation_uri: http://www.rubydoc.info/gems/faraday-gzip/3.0.1
185
- homepage_uri: https://github.com/bodrovis/faraday-gzip
166
+ documentation_uri: http://www.rubydoc.info/gems/faraday-gzip/3.0.3
186
167
  source_code_uri: https://github.com/bodrovis/faraday-gzip
187
168
  rubygems_mfa_required: 'true'
188
- post_install_message:
189
169
  rdoc_options: []
190
170
  require_paths:
191
171
  - lib
@@ -200,8 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
180
  - !ruby/object:Gem::Version
201
181
  version: '0'
202
182
  requirements: []
203
- rubygems_version: 3.5.22
204
- signing_key:
183
+ rubygems_version: 3.6.5
205
184
  specification_version: 4
206
185
  summary: Automatically sets compression headers and decompresses the response
207
186
  test_files: []
@@ -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
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe 'Faraday::Gzip::VERSION' do
4
- subject { Object.const_get(self.class.description) }
5
-
6
- it { is_expected.to match(/^\d+\.\d+\.\d+(\.\w+(\.\d+)?)?$/) }
7
- 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