faraday-gzip 1.0.0-java

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 02db240267d5516b8d1f24367dd7117ec77fcaa65b5a1009c1be347cdf129aa4
4
+ data.tar.gz: fa8c0dc6ee7de09af3bcdadcb12da10f6dcda31f0fb16e0468517cb3198bbe0c
5
+ SHA512:
6
+ metadata.gz: 8aa173f7e4836a945c8dea7fecfd94b6b0ff694a3d49005ee946ac30e29cad09c18f39838f1822981987e8ee1c2e6b157b60e1e4e4854ebf232d4f7588214dca
7
+ data.tar.gz: 6130653202bfe8f6cdd38d76a4c93c6f8b0fe829920080bfaf277f152739dfb0b8e1b80f6ed1e4d68b796eb9d8e7b4d2939675224a134b236f9b351396e49409
data/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0 (27-Dec-2022)
4
+
5
+ * Added support for JRuby (thanks, @ashkulz)
6
+ * Test with Ruby 3.2
7
+ * Minor updates
8
+
9
+ ## 0.1.0 (04-Feb-2022)
10
+
11
+ * First stable release.
12
+
13
+ ## 0.1.0.rc1
14
+
15
+ * Initial release.
data/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) 2022 Ilya Krukowski
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in
12
+ all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # Faraday Gzip
2
+
3
+ ![CI](https://github.com/bodrovis/faraday-gzip/actions/workflows/ci.yaml/badge.svg)
4
+ [![Gem](https://img.shields.io/gem/v/faraday-gzip.svg?style=flat-square)](https://rubygems.org/gems/faraday-gzip)
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.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'faraday-gzip'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ ```shell
19
+ bundle install
20
+ ```
21
+
22
+ Or install it yourself as:
23
+
24
+ ```shell
25
+ gem install faraday-gzip
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ ```ruby
31
+ require 'faraday/gzip'
32
+
33
+ conn = Faraday.new(...) do |f|
34
+ f.request :gzip
35
+ #...
36
+ end
37
+ ```
38
+
39
+ ## Development
40
+
41
+ After checking out the repo, run `bin/setup` to install dependencies.
42
+
43
+ Then, run `bin/test` to run the tests.
44
+
45
+ To install this gem onto your local machine, run `rake build`.
46
+
47
+ To release a new version, make a commit with a message such as "Bumped to 0.0.2" and then run `rake release`.
48
+ See how it works [here](https://bundler.io/guides/creating_gem.html#releasing-the-gem).
49
+
50
+ ## Contributing
51
+
52
+ Bug reports and pull requests are welcome on GitHub.
53
+
54
+ ## License
55
+
56
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zlib'
4
+
5
+ module Faraday
6
+ module Gzip
7
+ # Middleware to automatically decompress response bodies. If the
8
+ # "Accept-Encoding" header wasn't set in the request, this sets it to
9
+ # "gzip,deflate" and appropriately handles the compressed response from the
10
+ # server. This resembles what Ruby 1.9+ does internally in Net::HTTP#get.
11
+ # Based on https://github.com/lostisland/faraday_middleware/blob/main/lib/faraday_middleware/gzip.rb
12
+
13
+ class Middleware < Faraday::Middleware
14
+ def self.optional_dependency(lib = nil)
15
+ lib ? require(lib) : yield
16
+ true
17
+ rescue LoadError, NameError
18
+ false
19
+ end
20
+
21
+ BROTLI_SUPPORTED = optional_dependency 'brotli'
22
+
23
+ def self.supported_encodings
24
+ encodings = %w[gzip deflate]
25
+ encodings << 'br' if BROTLI_SUPPORTED
26
+ encodings
27
+ end
28
+
29
+ ACCEPT_ENCODING = 'Accept-Encoding'
30
+ CONTENT_ENCODING = 'Content-Encoding'
31
+ CONTENT_LENGTH = 'Content-Length'
32
+ SUPPORTED_ENCODINGS = supported_encodings.join(',').freeze
33
+
34
+ def call(env)
35
+ env[:request_headers][ACCEPT_ENCODING] ||= SUPPORTED_ENCODINGS
36
+ @app.call(env).on_complete do |response_env|
37
+ if response_env[:body].empty?
38
+ reset_body(response_env) { |body| raw_body(body) }
39
+ else
40
+ case response_env[:response_headers][CONTENT_ENCODING]
41
+ when 'gzip'
42
+ reset_body(response_env) { |body| uncompress_gzip(body) }
43
+ when 'deflate'
44
+ reset_body(response_env) { |body| inflate(body) }
45
+ when 'br'
46
+ reset_body(response_env) { |body| brotli_inflate(body) }
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ def reset_body(env)
53
+ env[:body] = yield(env[:body])
54
+ env[:response_headers].delete(CONTENT_ENCODING)
55
+ env[:response_headers][CONTENT_LENGTH] = env[:body].length
56
+ end
57
+
58
+ def uncompress_gzip(body)
59
+ io = StringIO.new(body)
60
+ gzip_reader = Zlib::GzipReader.new(io, encoding: 'ASCII-8BIT')
61
+ gzip_reader.read
62
+ end
63
+
64
+ def inflate(body)
65
+ # Inflate as a DEFLATE (RFC 1950+RFC 1951) stream
66
+ Zlib::Inflate.inflate(body)
67
+ rescue Zlib::DataError
68
+ # Fall back to inflating as a "raw" deflate stream which
69
+ # Microsoft servers return
70
+ inflate = Zlib::Inflate.new(-Zlib::MAX_WBITS)
71
+ begin
72
+ inflate.inflate(body)
73
+ ensure
74
+ inflate.close
75
+ end
76
+ end
77
+
78
+ def brotli_inflate(body)
79
+ Brotli.inflate(body)
80
+ end
81
+
82
+ def raw_body(body)
83
+ body
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faraday
4
+ module Gzip
5
+ VERSION = '1.0.0'
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require_relative 'gzip/middleware'
5
+ require_relative 'gzip/version'
6
+
7
+ module Faraday
8
+ # Middleware main module.
9
+ module Gzip
10
+ Faraday::Request.register_middleware(gzip: Faraday::Gzip::Middleware)
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,187 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: faraday-gzip
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: java
6
+ authors:
7
+ - Ilya Krukowski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-12-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '1.0'
19
+ name: faraday
20
+ prerelease: false
21
+ type: :runtime
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
33
+ name: bundler
34
+ prerelease: false
35
+ type: :development
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '13.0'
47
+ name: rake
48
+ prerelease: false
49
+ type: :development
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.0'
55
+ - !ruby/object:Gem::Dependency
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '3.0'
61
+ name: rspec
62
+ prerelease: false
63
+ type: :development
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '0.22'
75
+ name: simplecov
76
+ prerelease: false
77
+ type: :development
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.22'
83
+ - !ruby/object:Gem::Dependency
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '1.32'
89
+ name: rubocop
90
+ prerelease: false
91
+ type: :development
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.32'
97
+ - !ruby/object:Gem::Dependency
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: 0.5.0
103
+ name: rubocop-packaging
104
+ prerelease: false
105
+ type: :development
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.5.0
111
+ - !ruby/object:Gem::Dependency
112
+ requirement: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '1.0'
117
+ name: rubocop-performance
118
+ prerelease: false
119
+ type: :development
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.0'
125
+ - !ruby/object:Gem::Dependency
126
+ requirement: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '2.11'
131
+ name: rubocop-rspec
132
+ prerelease: false
133
+ type: :development
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '2.11'
139
+ description: 'Faraday plugin to automatically set compression headers (GZip, Deflate,
140
+ Brotli) and decompress the response.
141
+
142
+ '
143
+ email:
144
+ - golosizpru@gmail.com
145
+ executables: []
146
+ extensions: []
147
+ extra_rdoc_files: []
148
+ files:
149
+ - CHANGELOG.md
150
+ - LICENSE.md
151
+ - README.md
152
+ - lib/faraday/gzip.rb
153
+ - lib/faraday/gzip/middleware.rb
154
+ - lib/faraday/gzip/version.rb
155
+ homepage: https://github.com/bodrovis/faraday-gzip
156
+ licenses:
157
+ - MIT
158
+ metadata:
159
+ bug_tracker_uri: https://github.com/bodrovis/faraday-gzip/issues
160
+ changelog_uri: https://github.com/bodrovis/faraday-gzip/blob/master/CHANGELOG.md
161
+ documentation_uri: http://www.rubydoc.info/gems/faraday-gzip/1.0.0
162
+ homepage_uri: https://github.com/bodrovis/faraday-gzip
163
+ source_code_uri: https://github.com/bodrovis/faraday-gzip
164
+ rubygems_mfa_required: 'true'
165
+ post_install_message:
166
+ rdoc_options: []
167
+ require_paths:
168
+ - lib
169
+ required_ruby_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '2.6'
174
+ - - "<"
175
+ - !ruby/object:Gem::Version
176
+ version: '4'
177
+ required_rubygems_version: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ requirements: []
183
+ rubygems_version: 3.4.1
184
+ signing_key:
185
+ specification_version: 4
186
+ summary: Automatically sets compression headers and decompresses the response
187
+ test_files: []