faraday-gzip 1.0.0 → 2.0.1

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: 37792a5792e1200b8dd6a1932ef1bb25db1281704fa151c86df89cb200db9207
4
- data.tar.gz: fb067ddad2efdebef70598517f33461a712d39a73bdc35b202c9b1aaf7445c6f
3
+ metadata.gz: 44ad7c4e9c57927b182f8da9719aeb71455cd664607582af5be4440d660c9015
4
+ data.tar.gz: cfd6528ad8d82ce76f1b62cddbd63e2af086dab192a62c1dc14e6603ae5f5a18
5
5
  SHA512:
6
- metadata.gz: 5c95de6697b17f968d73b679b11c1f41d155a5504eb9f7412692d1fe749e1a816fb321766be3f4988ad42408796fc33ee6378a224d54dc0f1fdacc0799a3972c
7
- data.tar.gz: b79ccdbdc1cc0e0177f6b1abb9e175f0ba5f30a4ff53dcd76861ae7dfdc3235b19d4a1ddc2a0fd55b339aabd382a41096d7f538f4a2093202a96e3e068a7342c
6
+ metadata.gz: 61a096ffcf59316c2c7a1e9be64f159e879887a4a56dbfe495268d4c70a7636944885307277dd62c1a705df063676a6526921a65d01a0436cf01331349a01828
7
+ data.tar.gz: 174bd0148dfcdc7e33acddb9c086629b37f8179905081c45ea4c35fb2e916c6f07c994a8065fce6b900aca34de1624e162330b185766f8c18a9d3edb6098c6f3
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.0.1 (02-Jan-2024)
4
+
5
+ * Handle cases when body is `nil` (thanks, @bendangelo)
6
+
7
+ ## 2.0.0 (21-Jul-2023)
8
+
9
+ * Use zlib version 3
10
+
3
11
  ## 1.0.0 (27-Dec-2022)
4
12
 
5
13
  * Added support for JRuby (thanks, @ashkulz)
data/README.md CHANGED
@@ -3,7 +3,11 @@
3
3
  ![CI](https://github.com/bodrovis/faraday-gzip/actions/workflows/ci.yaml/badge.svg)
4
4
  [![Gem](https://img.shields.io/gem/v/faraday-gzip.svg?style=flat-square)](https://rubygems.org/gems/faraday-gzip)
5
5
 
6
- The `Gzip` middleware adds the necessary `Accept-Encoding` headers and automatically decompresses the response. If the "Accept-Encoding" header wasn't set in the request, this sets it to "gzip,deflate" and appropriately handles the compressed response from the server. This resembles what Ruby does internally in Net::HTTP#get. If [Brotli](https://github.com/miyucy/brotli) is added to the Gemfile, it will also add "br" to the header.
6
+ The `Gzip` middleware for Faraday 1 and 2 adds the necessary `Accept-Encoding` headers and automatically decompresses the response. If the "Accept-Encoding" header wasn't set in the request, this sets it to "gzip,deflate" and appropriately handles the compressed response from the server. This resembles what Ruby does internally in Net::HTTP#get. If [Brotli](https://github.com/miyucy/brotli) is added to the Gemfile, it will also add "br" to the header.
7
+
8
+ ## Prerequisites
9
+
10
+ This gem is tested with Ruby 2.6+ and JRuby 9.3+. Faraday 1 and 2 is supported.
7
11
 
8
12
  ## Installation
9
13
 
@@ -28,10 +32,10 @@ gem install faraday-gzip
28
32
  ## Usage
29
33
 
30
34
  ```ruby
31
- require 'faraday/gzip'
35
+ require 'faraday/gzip' # <=== add this line
32
36
 
33
37
  conn = Faraday.new(...) do |f|
34
- f.request :gzip
38
+ f.request :gzip # <=== add this line
35
39
  #...
36
40
  end
37
41
  ```
@@ -34,7 +34,7 @@ module Faraday
34
34
  def call(env)
35
35
  env[:request_headers][ACCEPT_ENCODING] ||= SUPPORTED_ENCODINGS
36
36
  @app.call(env).on_complete do |response_env|
37
- if response_env[:body].empty?
37
+ if empty_body?(response_env)
38
38
  reset_body(response_env) { |body| raw_body(body) }
39
39
  else
40
40
  case response_env[:response_headers][CONTENT_ENCODING]
@@ -52,7 +52,8 @@ module Faraday
52
52
  def reset_body(env)
53
53
  env[:body] = yield(env[:body])
54
54
  env[:response_headers].delete(CONTENT_ENCODING)
55
- env[:response_headers][CONTENT_LENGTH] = env[:body].length
55
+
56
+ env[:response_headers][CONTENT_LENGTH] = env[:body].nil? ? 0 : env[:body].length
56
57
  end
57
58
 
58
59
  def uncompress_gzip(body)
@@ -82,6 +83,12 @@ module Faraday
82
83
  def raw_body(body)
83
84
  body
84
85
  end
86
+
87
+ private
88
+
89
+ def empty_body?(response_env)
90
+ response_env[:body].nil? || response_env[:body].empty?
91
+ end
85
92
  end
86
93
  end
87
94
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Faraday
4
4
  module Gzip
5
- VERSION = '1.0.0'
5
+ VERSION = '2.0.1'
6
6
  end
7
7
  end
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: 1.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Krukowski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-27 00:00:00.000000000 Z
11
+ date: 2024-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.1'
33
+ version: '3.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.1'
40
+ version: '3.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -172,7 +172,7 @@ licenses:
172
172
  metadata:
173
173
  bug_tracker_uri: https://github.com/bodrovis/faraday-gzip/issues
174
174
  changelog_uri: https://github.com/bodrovis/faraday-gzip/blob/master/CHANGELOG.md
175
- documentation_uri: http://www.rubydoc.info/gems/faraday-gzip/1.0.0
175
+ documentation_uri: http://www.rubydoc.info/gems/faraday-gzip/2.0.1
176
176
  homepage_uri: https://github.com/bodrovis/faraday-gzip
177
177
  source_code_uri: https://github.com/bodrovis/faraday-gzip
178
178
  rubygems_mfa_required: 'true'
@@ -194,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
194
  - !ruby/object:Gem::Version
195
195
  version: '0'
196
196
  requirements: []
197
- rubygems_version: 3.4.1
197
+ rubygems_version: 3.5.3
198
198
  signing_key:
199
199
  specification_version: 4
200
200
  summary: Automatically sets compression headers and decompresses the response