async-http-faraday 0.1.0

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
+ SHA1:
3
+ metadata.gz: 238a6bab740e92125fd3e8572d235273d7cc52a1
4
+ data.tar.gz: 639f87407eaf3005fe12f30de45b07f7d430dcba
5
+ SHA512:
6
+ metadata.gz: 71039649cdae54ded6503b1832aecb7e6929ee51dcb2645719aecd0bc24205ede8d187af768a58a36f7ea4567238df4ce9def3fe2d1ee9bb2dbd235a0b4ca2ec
7
+ data.tar.gz: d02b7a1eea8945adced494ab62339b909ad3be09e4fa0f594f6718c6ec587df4e4aaf431ae9cac53d6dfa31dc9fdacb71f26e1320839f3ac061c2bd8a27ada48
data/.editorconfig ADDED
@@ -0,0 +1,9 @@
1
+ root = true
2
+
3
+ [*.md]
4
+ indent_style = tab
5
+ indent_size = 4
6
+
7
+ [*]
8
+ indent_style = tab
9
+ indent_size = 4
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --warnings
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,20 @@
1
+ language: ruby
2
+ sudo: false
3
+ dist: trusty
4
+ cache: bundler
5
+
6
+ matrix:
7
+ include:
8
+ - rvm: 2.0
9
+ - rvm: 2.1
10
+ - rvm: 2.2
11
+ - rvm: 2.3
12
+ - rvm: 2.4
13
+ - rvm: jruby-head
14
+ env: JRUBY_OPTS="--debug -X+O"
15
+ - rvm: ruby-head
16
+ - rvm: rbx-3
17
+ allow_failures:
18
+ - rvm: ruby-head
19
+ - rvm: jruby-head
20
+ - rvm: rbx-3
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem 'simplecov'
7
+ gem 'coveralls', require: false
8
+ end
data/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # Async::HTTP::Faraday
2
+
3
+ Provides an adaptor for [Faraday] to perform async HTTP requests. If you are designing a new library, you should probably just use `Async::HTTP::Client` directly.
4
+
5
+ [![Build Status](https://secure.travis-ci.org/socketry/async-http-faraday.svg)](http://travis-ci.org/socketry/async-http-faraday)
6
+ [![Code Climate](https://codeclimate.com/github/socketry/async-http-faraday.svg)](https://codeclimate.com/github/socketry/async-http-faraday)
7
+ [![Coverage Status](https://coveralls.io/repos/socketry/async-http-faraday/badge.svg)](https://coveralls.io/r/socketry/async-http-faraday)
8
+
9
+ [async]: https://github.com/socketry/async
10
+ [async-io]: https://github.com/socketry/async-io
11
+ [Faraday]: https://github.com/lostisland/faraday
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'async-http-faraday'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install async-http-faraday
28
+
29
+ ## Usage
30
+
31
+ Here is how you set faraday to use `Async::HTTP`:
32
+
33
+ ```ruby
34
+ require 'async/http/faraday'
35
+
36
+ # Make it the global default:
37
+ Faraday.default_adapter = :async_http
38
+
39
+ # Per connection:
40
+ conn = Faraday.new(...) do |faraday|
41
+ faraday.adapter :async_http
42
+ end
43
+ ```
44
+
45
+ Here is how you make a request:
46
+
47
+ ```ruby
48
+ Async::Reactor.run do
49
+ response = conn.get("/index")
50
+ end
51
+ ```
52
+
53
+ ## Contributing
54
+
55
+ 1. Fork it
56
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
57
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
58
+ 4. Push to the branch (`git push origin my-new-feature`)
59
+ 5. Create new Pull Request
60
+
61
+ ## License
62
+
63
+ Released under the MIT license.
64
+
65
+ Copyright, 2015, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
66
+
67
+ Permission is hereby granted, free of charge, to any person obtaining a copy
68
+ of this software and associated documentation files (the "Software"), to deal
69
+ in the Software without restriction, including without limitation the rights
70
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
71
+ copies of the Software, and to permit persons to whom the Software is
72
+ furnished to do so, subject to the following conditions:
73
+
74
+ The above copyright notice and this permission notice shall be included in
75
+ all copies or substantial portions of the Software.
76
+
77
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
78
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
79
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
80
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
81
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
82
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
83
+ THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,71 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:test)
5
+
6
+ task :default => :test
7
+
8
+ task :server do
9
+ require 'async/reactor'
10
+ require 'async/http/server'
11
+
12
+ app = lambda do |env|
13
+ [200, {}, ["Hello World"]]
14
+ end
15
+
16
+ server = Async::HTTP::Server.new([
17
+ Async::IO::Endpoint.tcp('127.0.0.1', 9294, reuse_port: true)
18
+ ], app)
19
+
20
+ Async::Reactor.run do
21
+ server.run
22
+ end
23
+ end
24
+
25
+ task :client do
26
+ require 'async/reactor'
27
+ require 'async/http/client'
28
+
29
+ client = Async::HTTP::Client.new([
30
+ Async::IO::Endpoint.tcp('127.0.0.1', 9294, reuse_port: true)
31
+ ])
32
+
33
+ Async::Reactor.run do
34
+ response = client.get("/")
35
+
36
+ puts response.inspect
37
+ end
38
+ end
39
+
40
+ task :wrk do
41
+ require 'async/reactor'
42
+ require 'async/http/server'
43
+
44
+ app = lambda do |env|
45
+ [200, {}, ["Hello World"]]
46
+ end
47
+
48
+ server = Async::HTTP::Server.new([
49
+ Async::IO::Endpoint.tcp('127.0.0.1', 9294, reuse_port: true)
50
+ ], app)
51
+
52
+ process_count = Etc.nprocessors
53
+
54
+ pids = process_count.times.collect do
55
+ fork do
56
+ Async::Reactor.run do
57
+ server.run
58
+ end
59
+ end
60
+ end
61
+
62
+ url = "http://127.0.0.1:9294/"
63
+
64
+ connections = process_count
65
+ system("wrk", "-c", connections.to_s, "-d", "2", "-t", connections.to_s, url)
66
+
67
+ pids.each do |pid|
68
+ Process.kill(:KILL, pid)
69
+ Process.wait pid
70
+ end
71
+ end
@@ -0,0 +1,27 @@
1
+
2
+ require_relative 'lib/async/http/faraday/version'
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "async-http-faraday"
6
+ spec.version = Async::HTTP::Faraday::VERSION
7
+ spec.authors = ["Samuel Williams"]
8
+ spec.email = ["samuel.williams@oriontransfer.co.nz"]
9
+
10
+ spec.summary = "Provides an adaptor between async-http and faraday."
11
+ spec.homepage = "https://github.com/socketry/async-http"
12
+
13
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
14
+ f.match(%r{^(test|spec|features)/})
15
+ end
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_dependency("async-http", "~> 0.5")
20
+ spec.add_dependency("faraday")
21
+
22
+ spec.add_development_dependency "async-rspec", "~> 1.2"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rspec", "~> 3.6"
26
+ spec.add_development_dependency "rake"
27
+ end
@@ -0,0 +1,22 @@
1
+ # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require_relative "faraday/version"
22
+ require_relative "faraday/adapter"
@@ -0,0 +1,81 @@
1
+ # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require 'faraday'
22
+ require 'faraday/adapter'
23
+ require 'async/http/client'
24
+
25
+ module Async
26
+ module HTTP
27
+ module Faraday
28
+ class Adapter < ::Faraday::Adapter
29
+ def call(env)
30
+ super
31
+
32
+ client = HTTP::Client.new(endpoints_for(env).to_a)
33
+
34
+ response = client.send_request(env[:method], env[:url].request_uri, env[:request_headers], env[:body] || [])
35
+
36
+ save_response(env, response.status, response.body, response.headers, response.reason)
37
+
38
+ @app.call env
39
+ end
40
+
41
+ def endpoints_for(env)
42
+ return to_enum(:endpoints_for, env) unless block_given?
43
+
44
+ if url = env[:url]
45
+ port = url.port
46
+ port ||= url.scheme == 'https' ? 443 : 80
47
+
48
+ endpoint = Async::IO::Endpoint.tcp(url.hostname, port)
49
+
50
+ if url.scheme == 'https'
51
+ yield SecureEndpoint.new(endpoint, ssl_context: ssl_context_for(env[:ssl]))
52
+ else
53
+ yield endpoint
54
+ end
55
+ end
56
+ end
57
+
58
+ def ssl_context_for(options)
59
+ OpenSSL::SSL::SSLContext.new.tap do |context|
60
+ context.set_params(
61
+ verify_mode: options.fetch(:verify, true) ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE,
62
+ # cert_store: ssl_cert_store(ssl),
63
+ # cert: options[:client_cert],
64
+ # key: options[:client_key],
65
+ # ca_file: ssl[:ca_file],
66
+ # ca_path: ssl[:ca_path],
67
+ # verify_depth: ssl[:verify_depth],
68
+ # version: ssl[:version],
69
+ )
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ module Faraday
78
+ class Adapter
79
+ register_middleware :async_http => Async::HTTP::Faraday::Adapter
80
+ end
81
+ end
@@ -0,0 +1,27 @@
1
+ # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ module Async
22
+ module HTTP
23
+ module Faraday
24
+ VERSION = "0.1.0"
25
+ end
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: async-http-faraday
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Samuel Williams
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-02-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: async-http
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: async-rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
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.6'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.6'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
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
+ description:
98
+ email:
99
+ - samuel.williams@oriontransfer.co.nz
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".editorconfig"
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
+ - Gemfile
109
+ - README.md
110
+ - Rakefile
111
+ - async-http-faraday.gemspec
112
+ - lib/async/http/faraday.rb
113
+ - lib/async/http/faraday/adapter.rb
114
+ - lib/async/http/faraday/version.rb
115
+ homepage: https://github.com/socketry/async-http
116
+ licenses: []
117
+ metadata: {}
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.6.12
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: Provides an adaptor between async-http and faraday.
138
+ test_files: []