faraday-net_http_persistent 1.0.1 → 2.0.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: 44caf04aad587142b7d6ebb786306d7f3cf91d139a2ef62bd5e6a99945c5b6a2
4
- data.tar.gz: cfdf6d4e037ed256b8bd3fafcce2831a0001df12e9aea1ab29ba31b6bca43297
3
+ metadata.gz: f4da892e0d8f0da0870720d9be4fe02ba9a43b3ad02abef06a95cf1665c14dd8
4
+ data.tar.gz: fe2b3d188a12ace453e570c3d80d21075887c4e703746fe4e71b6c6d64cb528b
5
5
  SHA512:
6
- metadata.gz: 8222309ebdc5207b2af84cc989e214269f44482da71549bc34984ff54b217e14fed0a6dc7d9144e2272c1647e9bf74b644489a8cdab7c95c40829131c1ab06f4
7
- data.tar.gz: 9c0834069b4eeec053b43940f52f6c97ad428a7aab0f9c27f79a6f4fdff53cacfb485a3af2fa65e3f2793508835a98123415a6effb09a8027509031400dde4e8
6
+ metadata.gz: 31f8bb4f02d25a74f2a3bcc1f79f6deb2d2e097afd6a1d9eb29c5f33a4d6e097dc61d07a8412e1ba218972f60bb2ac41b12445b75c9c3f19d80dc2f636d5e64d
7
+ data.tar.gz: 45d15ddfe4306489388634c58f3f9c0c90b7da6e38000df13f7c49004d99f176614463faf2285d1824bb88785120fbab6a2248cd3a6cdd183e1e665227edd966
data/README.md CHANGED
@@ -7,34 +7,29 @@ This gem is a [Faraday][faraday] adapter for the [Net::HTTP::Persistent gem][net
7
7
 
8
8
  ## Installation
9
9
 
10
- Add this line to your application's Gemfile:
10
+ Add this to your application's Gemfile:
11
11
 
12
12
  ```ruby
13
- gem 'faraday-net_http_persistent'
13
+ gem 'faraday-net_http_persistent', '~> 2.0'
14
14
  ```
15
15
 
16
16
  And then execute:
17
17
 
18
18
  $ bundle
19
19
 
20
- Or install it yourself as:
21
-
22
- $ gem install faraday-net_http_persistent
23
-
24
20
  ## Usage
25
21
 
26
- Configure your Faraday connection to use this adapter instead of the default one:
27
-
28
22
  ```ruby
29
- connection = Faraday.new(url, conn_options) do |conn|
30
- # Your other middleware goes here...
31
- conn.adapter :net_http_persistent
23
+ require 'faraday/net_http_persistent'
24
+
25
+ conn = Faraday.new(...) do |f|
26
+ f.adapter :net_http_persistent, pool_size: 5 do |http|
27
+ # yields Net::HTTP::Persistent
28
+ http.idle_timeout = 100
29
+ end
32
30
  end
33
31
  ```
34
32
 
35
- For more information on how to setup your Faraday connection and adapters usage,
36
- please refer to the [Faraday Website][faraday-website].
37
-
38
33
  ## Development
39
34
 
40
35
  After checking out the repo, run `bin/setup` to install dependencies.
@@ -60,9 +55,9 @@ The gem is available as open source under the terms of the [MIT License][mit-lic
60
55
 
61
56
  This project is intended to be a safe, welcoming space for collaboration.
62
57
  Everyone interacting in the Faraday::Http project’s codebases, issue trackers,
63
- chat rooms and mailing lists is expected to follow the [code of conduct].
58
+ chat rooms and mailing lists is expected to follow the [code of conduct][code-of-conduct].
64
59
 
65
- [code-of-conduct]: https://github.com/lostisland/faraday-http/blob/master/.github/CODE_OF_CONDUCT.md
60
+ [code-of-conduct]: https://github.com/lostisland/faraday-http/blob/main/CODE_OF_CONDUCT.md
66
61
  [covenant]: http://contributor-covenant.org
67
62
  [faraday]: https://github.com/lostisland/faraday
68
63
  [faraday-website]: https://lostisland.github.io/faraday
@@ -1,11 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "faraday/net_http"
4
+ require "net/http/persistent"
5
+
3
6
  module Faraday
4
7
  class Adapter
5
8
  # Net::HTTP::Persistent adapter.
6
9
  class NetHttpPersistent < NetHttp
7
- dependency "net/http/persistent"
8
-
9
10
  private
10
11
 
11
12
  def net_http_connection(env)
@@ -13,18 +14,14 @@ module Faraday
13
14
  if Net::HTTP::Persistent.instance_method(:initialize)
14
15
  .parameters.first == %i[key name]
15
16
  options = {name: "Faraday"}
16
- if @connection_options.key?(:pool_size)
17
- options[:pool_size] = @connection_options[:pool_size]
18
- end
17
+ options[:pool_size] = @connection_options[:pool_size] if @connection_options.key?(:pool_size)
19
18
  Net::HTTP::Persistent.new(**options)
20
19
  else
21
20
  Net::HTTP::Persistent.new("Faraday")
22
21
  end
23
22
 
24
23
  proxy_uri = proxy_uri(env)
25
- if @cached_connection.proxy_uri != proxy_uri
26
- @cached_connection.proxy = proxy_uri
27
- end
24
+ @cached_connection.proxy = proxy_uri if @cached_connection.proxy_uri != proxy_uri
28
25
  @cached_connection
29
26
  end
30
27
 
@@ -50,15 +47,32 @@ module Faraday
50
47
  end
51
48
 
52
49
  def perform_request(http, env)
53
- http.request env[:url], create_request(env)
50
+ if env[:request].stream_response?
51
+ size = 0
52
+ yielded = false
53
+
54
+ http_response = http.request(env[:url], create_request(env)) do |response|
55
+ response.read_body do |chunk|
56
+ if chunk.bytesize.positive? || size.positive?
57
+ yielded = true
58
+ size += chunk.bytesize
59
+ env[:request].on_data.call(chunk, size)
60
+ end
61
+ end
62
+ end
63
+
64
+ env[:request].on_data.call(+"", 0) unless yielded
65
+ http_response.body = nil
66
+ http_response
67
+ else
68
+ http.request(env[:url], create_request(env))
69
+ end
54
70
  rescue Errno::ETIMEDOUT, Net::OpenTimeout => e
55
71
  raise Faraday::TimeoutError, e
56
72
  rescue Net::HTTP::Persistent::Error => e
57
73
  raise Faraday::TimeoutError, e if e.message.include? "Timeout"
58
74
 
59
- if e.message.include? "connection refused"
60
- raise Faraday::ConnectionFailed, e
61
- end
75
+ raise Faraday::ConnectionFailed, e if e.message.include? "connection refused"
62
76
 
63
77
  raise
64
78
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Faraday
4
4
  module NetHttpPersistent
5
- VERSION = "1.0.1"
5
+ VERSION = "2.0.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,37 +1,37 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faraday-net_http_persistent
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Rogers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-19 00:00:00.000000000 Z
11
+ date: 2022-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: net-http-persistent
14
+ name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.1'
19
+ version: '2.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '3.1'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: bundler
28
+ name: faraday-net_http
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '2.0'
34
- type: :development
34
+ type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
@@ -39,103 +39,19 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: faraday
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '1.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '1.0'
55
- - !ruby/object:Gem::Dependency
56
- name: rake
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '13.0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '13.0'
69
- - !ruby/object:Gem::Dependency
70
- name: rspec
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '3.0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '3.0'
83
- - !ruby/object:Gem::Dependency
84
- name: simplecov
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: 0.19.0
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: 0.19.0
97
- - !ruby/object:Gem::Dependency
98
- name: standardrb
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '1.0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '1.0'
111
- - !ruby/object:Gem::Dependency
112
- name: multipart-parser
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: 0.1.1
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: 0.1.1
125
- - !ruby/object:Gem::Dependency
126
- name: webmock
42
+ name: net-http-persistent
127
43
  requirement: !ruby/object:Gem::Requirement
128
44
  requirements:
129
45
  - - "~>"
130
46
  - !ruby/object:Gem::Version
131
- version: '3.4'
132
- type: :development
47
+ version: '4.0'
48
+ type: :runtime
133
49
  prerelease: false
134
50
  version_requirements: !ruby/object:Gem::Requirement
135
51
  requirements:
136
52
  - - "~>"
137
53
  - !ruby/object:Gem::Version
138
- version: '3.4'
54
+ version: '4.0'
139
55
  description: Faraday adapter for NetHttpPersistent
140
56
  email:
141
57
  - me@mikerogers.io
@@ -154,7 +70,7 @@ licenses:
154
70
  metadata:
155
71
  homepage_uri: https://github.com/lostisland/faraday-net_http_persistent
156
72
  source_code_uri: https://github.com/lostisland/faraday-net_http_persistent
157
- changelog_uri: https://github.com/lostisland/faraday-net_http_persistent
73
+ changelog_uri: https://github.com/lostisland/faraday-net_http_persistent/releases/tag/v2.0.0
158
74
  post_install_message:
159
75
  rdoc_options: []
160
76
  require_paths:
@@ -163,14 +79,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
163
79
  requirements:
164
80
  - - ">="
165
81
  - !ruby/object:Gem::Version
166
- version: 2.4.0
82
+ version: 2.6.0
167
83
  required_rubygems_version: !ruby/object:Gem::Requirement
168
84
  requirements:
169
85
  - - ">="
170
86
  - !ruby/object:Gem::Version
171
87
  version: '0'
172
88
  requirements: []
173
- rubygems_version: 3.1.4
89
+ rubygems_version: 3.1.6
174
90
  signing_key:
175
91
  specification_version: 4
176
92
  summary: Faraday adapter for NetHttpPersistent