faraday-typhoeus 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/faraday/adapter/typhoeus.rb +6 -27
- data/lib/faraday/typhoeus/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3406a70221d241d3ccb2342afbc7fb08b553a773ac905347c4d564ad5f00c5c0
|
4
|
+
data.tar.gz: debb8619126869d93830f5032f5a96c59654cd2e5067dd6b675bf0f32c4fb3ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9d8adf166c150c68ec34dc6eb65fd08cd70e0659b7b01a8c7df0a5602fa76cbf4bb505ab5dfaf8a0cbc279aa359902b99bfc213be4febcbac675e1b5ef2dcc2
|
7
|
+
data.tar.gz: 45049261f119410adecc2fcee9c1f30151928ee80859bb56bcedfe9073b2e21dc9fd418cfe892f7db7b9b9fda0947e50c8a1f066f2363c8541ae4edc4b916ca3
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Faraday Typhoeus Adapter
|
2
2
|
|
3
|
-
This is a [Faraday][faraday] adapter for the [Typhoeus][typhoeus] parallel HTTP client. It supports parallel HTTP requests and streaming.
|
3
|
+
This is a [Faraday 2][faraday] adapter for the [Typhoeus][typhoeus] parallel HTTP client. It supports parallel HTTP requests and streaming.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -125,8 +125,8 @@ To release a new version, update the version number in `version.rb`, and then ru
|
|
125
125
|
- [ ] Better tests for parallel functionality (can port them over from Typhoeus)
|
126
126
|
- [ ] Support block-based configuration like other adapters
|
127
127
|
- [ ] Refactor the adapter a bit to look more like other Faraday 2 adapters (use `connection` etc.)
|
128
|
-
- [
|
129
|
-
- [
|
128
|
+
- [x] Compression support
|
129
|
+
- [x] Reason-phrase parsing support
|
130
130
|
|
131
131
|
## Contributing
|
132
132
|
|
@@ -4,25 +4,9 @@ require 'typhoeus'
|
|
4
4
|
|
5
5
|
module Faraday
|
6
6
|
class Adapter
|
7
|
-
# This class provides the main implementation for your adapter.
|
8
|
-
# There are some key responsibilities that your adapter should satisfy:
|
9
|
-
# * Initialize and store internally the client you chose (e.g. Net::HTTP)
|
10
|
-
# * Process requests and save the response (see `#call`)
|
11
7
|
class Typhoeus < Faraday::Adapter
|
12
8
|
self.supports_parallel = true
|
13
9
|
|
14
|
-
# The initialize method is lazy-called ONCE when the connection stack is
|
15
|
-
# built. See https://github.com/lostisland/faraday/blob/master/lib/faraday/rack_builder.rb
|
16
|
-
#
|
17
|
-
# @param app [#call] the "rack app" wrapped in middleware. See
|
18
|
-
# https://github.com/lostisland/faraday/blob/master/lib/faraday/rack_builder.rb#L157
|
19
|
-
# @param opts [Hash] the options hash with all the options necessary for
|
20
|
-
# the adapter to correctly configure itself. These are automatically
|
21
|
-
# stored into `@connection_options` when you call `super`.
|
22
|
-
def initialize(app = nil, opts = {}, &block)
|
23
|
-
super(app, opts, &block)
|
24
|
-
end
|
25
|
-
|
26
10
|
# Setup Hydra with provided options.
|
27
11
|
#
|
28
12
|
# @example Setup Hydra.
|
@@ -43,14 +27,6 @@ module Faraday
|
|
43
27
|
perform_request env
|
44
28
|
@app.call(env)
|
45
29
|
|
46
|
-
# NOTE: An adapter `call` MUST return the `env.response`. If
|
47
|
-
# `save_response` is the last line in your `call` method implementation,
|
48
|
-
# it will automatically return the response for you. Otherwise, you'll
|
49
|
-
# need to manually do so. You can do this with any (not both) of the
|
50
|
-
# following lines:
|
51
|
-
# * @app.call(env)
|
52
|
-
# * env.response
|
53
|
-
#
|
54
30
|
# Finally, it's good practice to rescue client-specific exceptions (e.g.
|
55
31
|
# Timeout, ConnectionFailed, etc...) and re-raise them as Faraday
|
56
32
|
# Errors. Check `Faraday::Error` for a list of all errors.
|
@@ -103,8 +79,9 @@ module Faraday
|
|
103
79
|
req.on_complete do |resp|
|
104
80
|
if resp.timed_out?
|
105
81
|
env[:typhoeus_timed_out] = true
|
82
|
+
env[:typhoeus_return_message] = resp.return_message
|
106
83
|
unless parallel?(env)
|
107
|
-
raise Faraday::TimeoutError,
|
84
|
+
raise Faraday::TimeoutError, resp.return_message
|
108
85
|
end
|
109
86
|
elsif resp.response_code.zero? || ((resp.return_code != :ok) && !resp.mock?)
|
110
87
|
env[:typhoeus_connection_failed] = true
|
@@ -114,7 +91,7 @@ module Faraday
|
|
114
91
|
end
|
115
92
|
end
|
116
93
|
|
117
|
-
save_response(env, resp.code, resp.body) do |response_headers|
|
94
|
+
save_response(env, resp.code, resp.body, nil, resp.status_message) do |response_headers|
|
118
95
|
response_headers.parse resp.response_headers
|
119
96
|
end
|
120
97
|
# in async mode, :response is initialized at this point
|
@@ -128,7 +105,9 @@ module Faraday
|
|
128
105
|
opts = {
|
129
106
|
method: env[:method],
|
130
107
|
body: env[:body],
|
131
|
-
headers: env[:request_headers]
|
108
|
+
headers: env[:request_headers],
|
109
|
+
# https://curl.se/libcurl/c/CURLOPT_ACCEPT_ENCODING.html
|
110
|
+
accept_encoding: ''
|
132
111
|
}.merge(@connection_options)
|
133
112
|
|
134
113
|
::Typhoeus::Request.new(env[:url].to_s, opts)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday-typhoeus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Leavitt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-04-
|
11
|
+
date: 2022-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|