faraday-net_http_persistent 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.md +21 -0
- data/README.md +71 -0
- data/lib/faraday/adapter/net_http_persistent.rb +91 -0
- data/lib/faraday/net_http_persistent.rb +17 -0
- data/lib/faraday/net_http_persistent/version.rb +7 -0
- metadata +177 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: aa61ff93e933ae7f0b110d990b79cbd1d3da4145b1d2f22707ae9a3ed17d5f33
|
4
|
+
data.tar.gz: 526386008ce11a13ab1bad9bbb29934a6871ed89cee091a80196a0db75e14b34
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ff1391332d7dbda1a225065917b7e6daff2bab5ddf81ea958c4c4ec928046625e6ce891377996af8396791d6c2dc5a5e1ee6fe53acfd4b4fa5f8b985daafd706
|
7
|
+
data.tar.gz: ae90175e679838e43034efaf16fcb10b18c42c99d6a319f71a77fe772df7f652012db5ae679999d0591c189fa442fe45b8f220c125e094fa8fbe5add424c1d3b
|
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Jan van der Pas
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# Faraday::NetHttpPersistent
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/faraday-net_http_persistent.svg)](https://rubygems.org/gems/faraday-net_http_persistent)
|
4
|
+
[![GitHub Actions CI](https://github.com/lostisland/faraday-net_http_persistent/workflows/CI/badge.svg)](https://github.com/lostisland/faraday-net_http_persistent/actions?query=workflow%3ACI)
|
5
|
+
|
6
|
+
This gem is a [Faraday][faraday] adapter for the [Net::HTTP::Persistent gem][net-http-persistent].
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'faraday-net_http_persistent'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install faraday-net_http_persistent
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
Configure your Faraday connection to use this adapter instead of the default one:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
connection = Faraday.new(url, conn_options) do |conn|
|
30
|
+
# Your other middleware goes here...
|
31
|
+
conn.adapter :net_http_persistent
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
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
|
+
## Development
|
39
|
+
|
40
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
41
|
+
Then, run `rake spec` to run the tests. You can also run `bin/console`
|
42
|
+
for an interactive prompt that will allow you to experiment.
|
43
|
+
|
44
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
45
|
+
To release a new version, update the version number in `version.rb`,
|
46
|
+
and then run `bundle exec rake release`, which will create a git tag for the version,
|
47
|
+
push git commits and tags, and push the `.gem` file to [rubygems.org].
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/lostisland/faraday-net_http_persistent.
|
52
|
+
This project is intended to be a safe, welcoming space for collaboration,
|
53
|
+
and contributors are expected to adhere to the [Contributor Covenant][covenant] code of conduct.
|
54
|
+
|
55
|
+
## License
|
56
|
+
|
57
|
+
The gem is available as open source under the terms of the [MIT License][mit-license].
|
58
|
+
|
59
|
+
## Code of Conduct
|
60
|
+
|
61
|
+
This project is intended to be a safe, welcoming space for collaboration.
|
62
|
+
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].
|
64
|
+
|
65
|
+
[code-of-conduct]: https://github.com/lostisland/faraday-http/blob/master/.github/CODE_OF_CONDUCT.md
|
66
|
+
[covenant]: http://contributor-covenant.org
|
67
|
+
[faraday]: https://github.com/lostisland/faraday
|
68
|
+
[faraday-website]: https://lostisland.github.io/faraday
|
69
|
+
[net-http-persistent]: https://github.com/drbrain/net-http-persistent
|
70
|
+
[mit-license]: https://opensource.org/licenses/MIT
|
71
|
+
[rubygems.org]: https://rubygems.org
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Faraday
|
4
|
+
class Adapter
|
5
|
+
# Net::HTTP::Persistent adapter.
|
6
|
+
class NetHttpPersistent < NetHttp
|
7
|
+
dependency "net/http/persistent"
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def net_http_connection(env)
|
12
|
+
@cached_connection ||=
|
13
|
+
if Net::HTTP::Persistent.instance_method(:initialize)
|
14
|
+
.parameters.first == %i[key name]
|
15
|
+
options = {name: "Faraday"}
|
16
|
+
if @connection_options.key?(:pool_size)
|
17
|
+
options[:pool_size] = @connection_options[:pool_size]
|
18
|
+
end
|
19
|
+
Net::HTTP::Persistent.new(**options)
|
20
|
+
else
|
21
|
+
Net::HTTP::Persistent.new("Faraday")
|
22
|
+
end
|
23
|
+
|
24
|
+
proxy_uri = proxy_uri(env)
|
25
|
+
if @cached_connection.proxy_uri != proxy_uri
|
26
|
+
@cached_connection.proxy = proxy_uri
|
27
|
+
end
|
28
|
+
@cached_connection
|
29
|
+
end
|
30
|
+
|
31
|
+
def proxy_uri(env)
|
32
|
+
proxy_uri = nil
|
33
|
+
if (proxy = env[:request][:proxy])
|
34
|
+
proxy_uri = if proxy[:uri].is_a?(::URI::HTTP)
|
35
|
+
proxy[:uri].dup
|
36
|
+
else
|
37
|
+
::URI.parse(proxy[:uri].to_s)
|
38
|
+
end
|
39
|
+
proxy_uri.user = proxy_uri.password = nil
|
40
|
+
# awful patch for net-http-persistent 2.8
|
41
|
+
# not unescaping user/password
|
42
|
+
if proxy[:user]
|
43
|
+
(class << proxy_uri; self; end).class_eval do
|
44
|
+
define_method(:user) { proxy[:user] }
|
45
|
+
define_method(:password) { proxy[:password] }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
proxy_uri
|
50
|
+
end
|
51
|
+
|
52
|
+
def perform_request(http, env)
|
53
|
+
http.request env[:url], create_request(env)
|
54
|
+
rescue Errno::ETIMEDOUT, Net::OpenTimeout => e
|
55
|
+
raise Faraday::TimeoutError, e
|
56
|
+
rescue Net::HTTP::Persistent::Error => e
|
57
|
+
raise Faraday::TimeoutError, e if e.message.include? "Timeout"
|
58
|
+
|
59
|
+
if e.message.include? "connection refused"
|
60
|
+
raise Faraday::ConnectionFailed, e
|
61
|
+
end
|
62
|
+
|
63
|
+
raise
|
64
|
+
end
|
65
|
+
|
66
|
+
SSL_CONFIGURATIONS = {
|
67
|
+
certificate: :client_cert,
|
68
|
+
private_key: :client_key,
|
69
|
+
ca_file: :ca_file,
|
70
|
+
ssl_version: :version,
|
71
|
+
min_version: :min_version,
|
72
|
+
max_version: :max_version
|
73
|
+
}.freeze
|
74
|
+
|
75
|
+
def configure_ssl(http, ssl)
|
76
|
+
return unless ssl
|
77
|
+
|
78
|
+
http_set(http, :verify_mode, ssl_verify_mode(ssl))
|
79
|
+
http_set(http, :cert_store, ssl_cert_store(ssl))
|
80
|
+
|
81
|
+
SSL_CONFIGURATIONS
|
82
|
+
.select { |_, key| ssl[key] }
|
83
|
+
.each { |target, key| http_set(http, target, ssl[key]) }
|
84
|
+
end
|
85
|
+
|
86
|
+
def http_set(http, attr, value)
|
87
|
+
http.send("#{attr}=", value) if http.send(attr) != value
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "adapter/net_http_persistent"
|
4
|
+
require_relative "net_http_persistent/version"
|
5
|
+
|
6
|
+
module Faraday
|
7
|
+
module NetHttpPersistent
|
8
|
+
# Faraday allows you to register your middleware for easier configuration.
|
9
|
+
# This step is totally optional, but it basically allows users to use a custom symbol (in this case, `:net_http_persistent`),
|
10
|
+
# to use your adapter in their connections.
|
11
|
+
# After calling this line, the following are both valid ways to set the adapter in a connection:
|
12
|
+
# * conn.adapter Faraday::Adapter::NetNttpPersistent
|
13
|
+
# * conn.adapter :net_http_persistent
|
14
|
+
# Without this line, only the former method is valid.
|
15
|
+
Faraday::Adapter.register_middleware(net_http_persistent: Faraday::Adapter::NetHttpPersistent)
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: faraday-net_http_persistent
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mike Rogers
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-03-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
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
|
+
name: net-http-persistent
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.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
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '3.4'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '3.4'
|
139
|
+
description: Faraday adapter for NetHttpPersistent
|
140
|
+
email:
|
141
|
+
- me@mikerogers.io
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- LICENSE.md
|
147
|
+
- README.md
|
148
|
+
- lib/faraday/adapter/net_http_persistent.rb
|
149
|
+
- lib/faraday/net_http_persistent.rb
|
150
|
+
- lib/faraday/net_http_persistent/version.rb
|
151
|
+
homepage: https://github.com/lostisland/faraday-net_http_persistent
|
152
|
+
licenses:
|
153
|
+
- MIT
|
154
|
+
metadata:
|
155
|
+
homepage_uri: https://github.com/lostisland/faraday-net_http_persistent
|
156
|
+
source_code_uri: https://github.com/lostisland/faraday-net_http_persistent
|
157
|
+
changelog_uri: https://github.com/lostisland/faraday-net_http_persistent
|
158
|
+
post_install_message:
|
159
|
+
rdoc_options: []
|
160
|
+
require_paths:
|
161
|
+
- lib
|
162
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 2.4.0
|
167
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
168
|
+
requirements:
|
169
|
+
- - ">="
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
version: '0'
|
172
|
+
requirements: []
|
173
|
+
rubygems_version: 3.1.4
|
174
|
+
signing_key:
|
175
|
+
specification_version: 4
|
176
|
+
summary: Faraday adapter for NetHttpPersistent
|
177
|
+
test_files: []
|