faraday-http 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0a6f0a75350d4a13a2c1e6c73d53c5a7302fc058a63c83324c80096cb85422e5
4
+ data.tar.gz: 80d6a69972f48eee45fe9d03f42da67463461b75245c718664f6968b2e4f5406
5
+ SHA512:
6
+ metadata.gz: e5d2a37bfa87b73788150387ff7fe85160356a20aeb76b3484fbba4d79373986a430fc9bb8962ea75ab865a78c73a4078159983fdfd5a90d29f12b013e7126bf
7
+ data.tar.gz: eb2ea51bd852b70514e17a4f7f08a391d0404b9b742db1f71e6019243580d3118d3fab3cfa19462bc0c1abe98f3b9cdffec0d6fd0abc9d72cdfbcb45b8bc7982
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 lostisland
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,71 @@
1
+ # Faraday::Http
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/faraday-http.svg)](https://rubygems.org/gems/faraday-http)
4
+ [![GitHub Actions CI](https://github.com/lostisland/faraday-http/workflows/CI/badge.svg)](https://github.com/lostisland/faraday-http/actions?query=workflow%3ACI)
5
+
6
+ This gem is a [Faraday][faraday] adapter for the [http.rb gem][http-gem].
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'faraday-http'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install faraday-http
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 :http
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-http.
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
+ [http-gem]: https://github.com/httprb/http
70
+ [mit-license]: https://opensource.org/licenses/MIT
71
+ [rubygems.org]: https://rubygems.org
@@ -0,0 +1,124 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faraday
4
+ class Adapter
5
+ # HTTP.rb adapter.
6
+ class HTTP < Faraday::Adapter
7
+ dependency 'http'
8
+
9
+ # Takes the environment and performs the request.
10
+ #
11
+ # @param env [Faraday::Env] the request environment.
12
+ #
13
+ # @return [Faraday::Response] the response.
14
+ def call(env)
15
+ super
16
+ perform_request(env)
17
+ @app.call(env)
18
+ end
19
+
20
+ private
21
+
22
+ def perform_request(env)
23
+ conn = setup_connection(env)
24
+
25
+ resp = conn.request env[:method], env[:url],
26
+ body: env[:body],
27
+ ssl_context: ssl_context(env[:ssl])
28
+
29
+ save_response(env, resp.code, resp.body.to_s, resp.headers, resp.status.reason)
30
+ rescue ::HTTP::TimeoutError
31
+ raise Faraday::TimeoutError, $ERROR_INFO
32
+ rescue ::HTTP::ConnectionError
33
+ raise Faraday::ConnectionFailed, $ERROR_INFO
34
+ rescue StandardError => e
35
+ raise Faraday::SSLError, e if defined?(OpenSSL) && e.is_a?(OpenSSL::SSL::SSLError)
36
+
37
+ raise
38
+ end
39
+
40
+ def setup_connection(env)
41
+ conn = ::HTTP
42
+
43
+ request_config(conn, env[:request]) if env[:request]
44
+ conn.headers(env.request_headers)
45
+ end
46
+
47
+ def request_config(conn, config)
48
+ if (timeout = config[:timeout])
49
+ conn = conn.timeout(connect: timeout, read: timeout, write: timeout)
50
+ end
51
+
52
+ if (timeout = config[:open_timeout])
53
+ conn = conn.timeout(connect: timeout, write: timeout)
54
+ end
55
+
56
+ if (proxy = config[:proxy])
57
+ conn = conn.via(proxy.uri.host, proxy.uri.port, proxy.user, proxy.password)
58
+ end
59
+
60
+ conn
61
+ end
62
+
63
+ def ssl_context(ssl)
64
+ params = {}
65
+ %i[
66
+ ca_file ca_path cert_store verify_depth
67
+ ].each do |key|
68
+ if (value = ssl[key])
69
+ params[key] = value
70
+ end
71
+ end
72
+
73
+ if (client_cert = ssl_client_cert(ssl.client_cert))
74
+ params[:cert] = client_cert
75
+ end
76
+
77
+ if (client_key = ssl_client_key(ssl.client_key))
78
+ params[:key] = client_key
79
+ end
80
+
81
+ OpenSSL::SSL::SSLContext.new.tap do |ctx|
82
+ ctx.set_params(params)
83
+ if (vm = ssl.verify_mode)
84
+ ctx.verify_mode = vm
85
+ elsif ssl.disable?
86
+ ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
87
+ end
88
+
89
+ if (v = ssl.version)
90
+ ctx.ssl_version = v
91
+ end
92
+
93
+ if ctx.respond_to?(:min_version=) && (v = ssl.min_version)
94
+ ctx.min_version = v
95
+ end
96
+ end
97
+ end
98
+
99
+ def ssl_client_cert(cert)
100
+ case cert
101
+ when NilClass then nil
102
+ when String
103
+ OpenSSL::X509::Certificate.new(File.read(cert))
104
+ when OpenSSL::X509::Certificate
105
+ cert
106
+ else
107
+ raise Faraday::Error, "invalid ssl.client_cert: #{cert.inspect}"
108
+ end
109
+ end
110
+
111
+ def ssl_client_key(cert)
112
+ case cert
113
+ when NilClass then nil
114
+ when String
115
+ OpenSSL::PKey::RSA.new(File.read(cert))
116
+ when OpenSSL::PKey::RSA, OpenSSL::PKey::DSA
117
+ cert
118
+ else
119
+ raise Faraday::Error, "invalid ssl.client_key: #{cert.inspect}"
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'faraday/http/version'
5
+ require 'faraday/adapter/http'
6
+
7
+ # Extend the main Faraday module.
8
+ module Faraday
9
+ module Http
10
+ class Error < StandardError; end
11
+ end
12
+
13
+ Faraday::Adapter.register_middleware(http: Faraday::Adapter::HTTP)
14
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faraday
4
+ module Http
5
+ VERSION = '1.0.0'
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: faraday-http
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - iMacTia
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-05-08 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: http
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.0'
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'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.4'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.4'
111
+ description: Faraday Adapter for HTTP.rb
112
+ email:
113
+ - giuffrida.mattia@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - LICENSE
119
+ - README.md
120
+ - lib/faraday/adapter/http.rb
121
+ - lib/faraday/http.rb
122
+ - lib/faraday/http/version.rb
123
+ homepage: https://github.com/lostisland/faraday-http
124
+ licenses:
125
+ - MIT
126
+ metadata:
127
+ homepage_uri: https://github.com/lostisland/faraday-http
128
+ source_code_uri: https://github.com/lostisland/faraday-http
129
+ changelog_uri: https://github.com/lostisland/faraday-http/releases
130
+ post_install_message:
131
+ rdoc_options: []
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '2.5'
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ requirements: []
145
+ rubygems_version: 3.1.2
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: Faraday Adapter for HTTP.rb
149
+ test_files: []