twingly-http 0.5.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62b69e5cac842eeefbaad91288707eb474458da8df5074521652fccd486edc89
|
4
|
+
data.tar.gz: 33c81395fbfd3f1588452fb93b66a067c40521654042f0eb6f04acd8a362b0c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a95ad89c7bf1af645cb000bb739e8100048a268185e88d75ac307581f0832e85586f34fa1a4bc9f1f7291ca2147a2b9f61d032d562662a3f5a84aaca8750f3e
|
7
|
+
data.tar.gz: 4b79a8ea8a109fe5cbf0e57c0591e4a5382b10ba5bb5a05ada0ca96ed0197488fcf1e9bce47d0e1f61eb8d1ec016d5f1afec1338131a3b7b84388e85f35d2bf7
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Faraday
|
4
|
+
module ResponseBodySizeLimit
|
5
|
+
class LimitExceededError < StandardError; end
|
6
|
+
|
7
|
+
class Middleware < Faraday::Middleware
|
8
|
+
def initialize(app, max_size_bytes:)
|
9
|
+
super(app)
|
10
|
+
|
11
|
+
@max_size_bytes = max_size_bytes
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env) # rubocop:disable Metrics/MethodLength
|
15
|
+
response_body_size = 0
|
16
|
+
accumulated_body = + ""
|
17
|
+
|
18
|
+
env.request.on_data = proc do |chunk, _|
|
19
|
+
response_body_size += chunk.bytesize
|
20
|
+
accumulated_body << chunk
|
21
|
+
|
22
|
+
if response_body_size > @max_size_bytes
|
23
|
+
raise LimitExceededError,
|
24
|
+
"Response body too large, exceeced the configured max size of #{@max_size_bytes} bytes."
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
@app.call(env).on_complete do |response_env|
|
29
|
+
response_env.body = accumulated_body
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
Faraday::Request.register_middleware(
|
37
|
+
response_body_size_limit: Faraday::ResponseBodySizeLimit::Middleware
|
38
|
+
)
|
data/lib/twingly/http.rb
CHANGED
@@ -7,6 +7,7 @@ require "faraday_middleware"
|
|
7
7
|
|
8
8
|
require_relative "../faraday/logfmt_logger"
|
9
9
|
require_relative "../faraday/url_size_limit"
|
10
|
+
require_relative "../faraday/response_body_size_limit"
|
10
11
|
require_relative "heroku"
|
11
12
|
require_relative "string_utilities"
|
12
13
|
|
@@ -15,6 +16,7 @@ module Twingly
|
|
15
16
|
class ConnectionError < StandardError; end
|
16
17
|
class UrlSizeLimitExceededError < StandardError; end
|
17
18
|
class RedirectLimitReachedError < StandardError; end
|
19
|
+
class ResponseBodySizeLimitExceededError < StandardError; end
|
18
20
|
class Client # rubocop:disable Metrics/ClassLength
|
19
21
|
DEFAULT_RETRYABLE_EXCEPTIONS = [
|
20
22
|
Faraday::ConnectionFailed,
|
@@ -31,6 +33,7 @@ module Twingly
|
|
31
33
|
DEFAULT_NUMBER_OF_RETRIES = 0
|
32
34
|
DEFAULT_RETRY_INTERVAL = 1
|
33
35
|
DEFAULT_MAX_URL_SIZE_BYTES = Float::INFINITY
|
36
|
+
DEFAULT_MAX_RESPONSE_BODY_SIZE_BYTES = Float::INFINITY
|
34
37
|
DEFAULT_FOLLOW_REDIRECTS_LIMIT = 3
|
35
38
|
|
36
39
|
attr_writer :http_timeout
|
@@ -39,6 +42,7 @@ module Twingly
|
|
39
42
|
attr_writer :retry_interval
|
40
43
|
attr_writer :on_retry_callback
|
41
44
|
attr_writer :max_url_size_bytes
|
45
|
+
attr_writer :max_response_body_size_bytes
|
42
46
|
attr_writer :request_id
|
43
47
|
attr_writer :follow_redirects
|
44
48
|
|
@@ -46,9 +50,10 @@ module Twingly
|
|
46
50
|
attr_accessor :logger
|
47
51
|
attr_accessor :retryable_exceptions
|
48
52
|
|
49
|
-
def initialize(base_user_agent:, logger: default_logger)
|
53
|
+
def initialize(base_user_agent:, logger: default_logger, user_agent: nil)
|
50
54
|
@base_user_agent = base_user_agent
|
51
55
|
@logger = logger
|
56
|
+
@user_agent = user_agent
|
52
57
|
|
53
58
|
initialize_defaults
|
54
59
|
end
|
@@ -80,19 +85,20 @@ module Twingly
|
|
80
85
|
end
|
81
86
|
|
82
87
|
def initialize_defaults
|
83
|
-
@request_id
|
84
|
-
@http_timeout
|
85
|
-
@http_open_timeout
|
86
|
-
@retryable_exceptions
|
87
|
-
@number_of_retries
|
88
|
-
@retry_interval
|
89
|
-
@on_retry_callback
|
90
|
-
@follow_redirects
|
91
|
-
@follow_redirects_limit
|
92
|
-
@max_url_size_bytes
|
88
|
+
@request_id = nil
|
89
|
+
@http_timeout = DEFAULT_HTTP_TIMEOUT
|
90
|
+
@http_open_timeout = DEFAULT_HTTP_OPEN_TIMEOUT
|
91
|
+
@retryable_exceptions = DEFAULT_RETRYABLE_EXCEPTIONS
|
92
|
+
@number_of_retries = DEFAULT_NUMBER_OF_RETRIES
|
93
|
+
@retry_interval = DEFAULT_RETRY_INTERVAL
|
94
|
+
@on_retry_callback = nil
|
95
|
+
@follow_redirects = false
|
96
|
+
@follow_redirects_limit = DEFAULT_FOLLOW_REDIRECTS_LIMIT
|
97
|
+
@max_url_size_bytes = DEFAULT_MAX_URL_SIZE_BYTES
|
98
|
+
@max_response_body_size_bytes = DEFAULT_MAX_RESPONSE_BODY_SIZE_BYTES
|
93
99
|
end
|
94
100
|
|
95
|
-
def http_response_for(method, **args)
|
101
|
+
def http_response_for(method, **args) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
96
102
|
response = send("http_#{method}_response", **args)
|
97
103
|
|
98
104
|
Response.new(headers: response.headers.to_h,
|
@@ -105,6 +111,8 @@ module Twingly
|
|
105
111
|
raise UrlSizeLimitExceededError, error.message
|
106
112
|
rescue FaradayMiddleware::RedirectLimitReached => error
|
107
113
|
raise RedirectLimitReachedError, error.message
|
114
|
+
rescue Faraday::ResponseBodySizeLimit::LimitExceededError => error
|
115
|
+
raise ResponseBodySizeLimitExceededError, error.message
|
108
116
|
end
|
109
117
|
|
110
118
|
def http_get_response(url:, params:, headers:)
|
@@ -192,6 +200,8 @@ module Twingly
|
|
192
200
|
exceptions: @retryable_exceptions,
|
193
201
|
methods: [], # empty [] forces Faraday to run retry_if
|
194
202
|
retry_if: retry_if
|
203
|
+
faraday.request :response_body_size_limit,
|
204
|
+
max_size_bytes: @max_response_body_size_bytes
|
195
205
|
faraday.response :logfmt_logger, @logger.dup,
|
196
206
|
headers: true,
|
197
207
|
bodies: true,
|
@@ -232,7 +242,7 @@ module Twingly
|
|
232
242
|
end
|
233
243
|
|
234
244
|
def user_agent
|
235
|
-
format(
|
245
|
+
@user_agent || format(
|
236
246
|
"%<base>s (Release/%<release>s; Commit/%<commit>s)",
|
237
247
|
base: @base_user_agent,
|
238
248
|
release: Heroku.release_version,
|
data/lib/twingly/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twingly-http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Twingly AB
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -44,118 +44,6 @@ dependencies:
|
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: 1.0.0
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: climate_control
|
49
|
-
requirement: !ruby/object:Gem::Requirement
|
50
|
-
requirements:
|
51
|
-
- - "~>"
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '0.1'
|
54
|
-
type: :development
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
requirements:
|
58
|
-
- - "~>"
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: '0.1'
|
61
|
-
- !ruby/object:Gem::Dependency
|
62
|
-
name: rake
|
63
|
-
requirement: !ruby/object:Gem::Requirement
|
64
|
-
requirements:
|
65
|
-
- - "~>"
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version: '12'
|
68
|
-
type: :development
|
69
|
-
prerelease: false
|
70
|
-
version_requirements: !ruby/object:Gem::Requirement
|
71
|
-
requirements:
|
72
|
-
- - "~>"
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: '12'
|
75
|
-
- !ruby/object:Gem::Dependency
|
76
|
-
name: rspec
|
77
|
-
requirement: !ruby/object:Gem::Requirement
|
78
|
-
requirements:
|
79
|
-
- - "~>"
|
80
|
-
- !ruby/object:Gem::Version
|
81
|
-
version: '3'
|
82
|
-
type: :development
|
83
|
-
prerelease: false
|
84
|
-
version_requirements: !ruby/object:Gem::Requirement
|
85
|
-
requirements:
|
86
|
-
- - "~>"
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
version: '3'
|
89
|
-
- !ruby/object:Gem::Dependency
|
90
|
-
name: rubocop
|
91
|
-
requirement: !ruby/object:Gem::Requirement
|
92
|
-
requirements:
|
93
|
-
- - "~>"
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
version: 1.14.0
|
96
|
-
type: :development
|
97
|
-
prerelease: false
|
98
|
-
version_requirements: !ruby/object:Gem::Requirement
|
99
|
-
requirements:
|
100
|
-
- - "~>"
|
101
|
-
- !ruby/object:Gem::Version
|
102
|
-
version: 1.14.0
|
103
|
-
- !ruby/object:Gem::Dependency
|
104
|
-
name: rubocop-rspec
|
105
|
-
requirement: !ruby/object:Gem::Requirement
|
106
|
-
requirements:
|
107
|
-
- - "~>"
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: 2.4.0
|
110
|
-
type: :development
|
111
|
-
prerelease: false
|
112
|
-
version_requirements: !ruby/object:Gem::Requirement
|
113
|
-
requirements:
|
114
|
-
- - "~>"
|
115
|
-
- !ruby/object:Gem::Version
|
116
|
-
version: 2.4.0
|
117
|
-
- !ruby/object:Gem::Dependency
|
118
|
-
name: toxiproxy
|
119
|
-
requirement: !ruby/object:Gem::Requirement
|
120
|
-
requirements:
|
121
|
-
- - "~>"
|
122
|
-
- !ruby/object:Gem::Version
|
123
|
-
version: '1.0'
|
124
|
-
type: :development
|
125
|
-
prerelease: false
|
126
|
-
version_requirements: !ruby/object:Gem::Requirement
|
127
|
-
requirements:
|
128
|
-
- - "~>"
|
129
|
-
- !ruby/object:Gem::Version
|
130
|
-
version: '1.0'
|
131
|
-
- !ruby/object:Gem::Dependency
|
132
|
-
name: vcr
|
133
|
-
requirement: !ruby/object:Gem::Requirement
|
134
|
-
requirements:
|
135
|
-
- - "~>"
|
136
|
-
- !ruby/object:Gem::Version
|
137
|
-
version: '5.0'
|
138
|
-
type: :development
|
139
|
-
prerelease: false
|
140
|
-
version_requirements: !ruby/object:Gem::Requirement
|
141
|
-
requirements:
|
142
|
-
- - "~>"
|
143
|
-
- !ruby/object:Gem::Version
|
144
|
-
version: '5.0'
|
145
|
-
- !ruby/object:Gem::Dependency
|
146
|
-
name: webmock
|
147
|
-
requirement: !ruby/object:Gem::Requirement
|
148
|
-
requirements:
|
149
|
-
- - "~>"
|
150
|
-
- !ruby/object:Gem::Version
|
151
|
-
version: '3.7'
|
152
|
-
type: :development
|
153
|
-
prerelease: false
|
154
|
-
version_requirements: !ruby/object:Gem::Requirement
|
155
|
-
requirements:
|
156
|
-
- - "~>"
|
157
|
-
- !ruby/object:Gem::Version
|
158
|
-
version: '3.7'
|
159
47
|
description: Robust HTTP client tailored by Twingly
|
160
48
|
email:
|
161
49
|
- support@twingly.com
|
@@ -168,6 +56,8 @@ files:
|
|
168
56
|
- lib/faraday/logfmt_logger.rb
|
169
57
|
- lib/faraday/logfmt_logger/LICENSE.md
|
170
58
|
- lib/faraday/logfmt_logger/middleware.rb
|
59
|
+
- lib/faraday/response_body_size_limit.rb
|
60
|
+
- lib/faraday/response_body_size_limit/middleware.rb
|
171
61
|
- lib/faraday/url_size_limit.rb
|
172
62
|
- lib/faraday/url_size_limit/middleware.rb
|
173
63
|
- lib/twingly/heroku.rb
|
@@ -177,7 +67,8 @@ files:
|
|
177
67
|
homepage: http://github.com/twingly/twingly-http
|
178
68
|
licenses:
|
179
69
|
- MIT
|
180
|
-
metadata:
|
70
|
+
metadata:
|
71
|
+
rubygems_mfa_required: 'true'
|
181
72
|
post_install_message:
|
182
73
|
rdoc_options: []
|
183
74
|
require_paths:
|
@@ -193,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
193
84
|
- !ruby/object:Gem::Version
|
194
85
|
version: '0'
|
195
86
|
requirements: []
|
196
|
-
rubygems_version: 3.
|
87
|
+
rubygems_version: 3.5.4
|
197
88
|
signing_key:
|
198
89
|
specification_version: 4
|
199
90
|
summary: Robust HTTP client
|