typhoeus 1.6.0 → 1.7.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 +4 -4
- data/CHANGELOG.md +217 -1
- data/README.md +338 -160
- data/UPGRADE.md +29 -0
- data/lib/rack/typhoeus/middleware/params_decoder/helper.rb +67 -14
- data/lib/rack/typhoeus/middleware/params_decoder.rb +8 -19
- data/lib/rack/typhoeus.rb +2 -0
- data/lib/typhoeus/adapters/faraday.rb +89 -28
- data/lib/typhoeus/cache/dalli.rb +2 -0
- data/lib/typhoeus/cache/rails.rb +3 -1
- data/lib/typhoeus/cache/redis.rb +2 -0
- data/lib/typhoeus/config.rb +51 -7
- data/lib/typhoeus/easy_factory.rb +129 -23
- data/lib/typhoeus/errors/invalid_option.rb +23 -0
- data/lib/typhoeus/errors/no_response.rb +18 -0
- data/lib/typhoeus/errors/no_stub.rb +8 -1
- data/lib/typhoeus/errors/typhoeus_error.rb +2 -0
- data/lib/typhoeus/errors.rb +4 -0
- data/lib/typhoeus/expectation.rb +33 -1
- data/lib/typhoeus/hydra/queueable.rb +29 -4
- data/lib/typhoeus/hydra.rb +349 -21
- data/lib/typhoeus/pool.rb +80 -17
- data/lib/typhoeus/railtie.rb +4 -2
- data/lib/typhoeus/request/actions.rb +2 -0
- data/lib/typhoeus/request/callbacks.rb +11 -4
- data/lib/typhoeus/request/marshal.rb +5 -2
- data/lib/typhoeus/request/streamable.rb +2 -0
- data/lib/typhoeus/request.rb +317 -30
- data/lib/typhoeus/response/cacheable.rb +2 -0
- data/lib/typhoeus/response/header.rb +234 -14
- data/lib/typhoeus/response/informations.rb +75 -12
- data/lib/typhoeus/response/status.rb +4 -13
- data/lib/typhoeus/response.rb +35 -0
- data/lib/typhoeus/version.rb +3 -1
- data/lib/typhoeus.rb +89 -26
- data/typhoeus.gemspec +15 -3
- metadata +19 -22
- data/lib/typhoeus/hydra/addable.rb +0 -23
- data/lib/typhoeus/hydra/before.rb +0 -31
- data/lib/typhoeus/hydra/block_connection.rb +0 -35
- data/lib/typhoeus/hydra/cacheable.rb +0 -15
- data/lib/typhoeus/hydra/memoizable.rb +0 -56
- data/lib/typhoeus/hydra/runnable.rb +0 -19
- data/lib/typhoeus/hydra/stubbable.rb +0 -28
- data/lib/typhoeus/request/before.rb +0 -30
- data/lib/typhoeus/request/block_connection.rb +0 -52
- data/lib/typhoeus/request/cacheable.rb +0 -38
- data/lib/typhoeus/request/memoizable.rb +0 -38
- data/lib/typhoeus/request/operations.rb +0 -40
- data/lib/typhoeus/request/responseable.rb +0 -29
- data/lib/typhoeus/request/stubbable.rb +0 -30
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
module Typhoeus
|
|
2
|
-
class Hydra
|
|
3
|
-
|
|
4
|
-
# This module contains logic to run a hydra.
|
|
5
|
-
module Runnable
|
|
6
|
-
|
|
7
|
-
# Start the hydra run.
|
|
8
|
-
#
|
|
9
|
-
# @example Start hydra run.
|
|
10
|
-
# hydra.run
|
|
11
|
-
#
|
|
12
|
-
# @return [ Symbol ] Return value from multi.perform.
|
|
13
|
-
def run
|
|
14
|
-
dequeue_many
|
|
15
|
-
multi.perform
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
module Typhoeus
|
|
2
|
-
class Hydra
|
|
3
|
-
|
|
4
|
-
# This module handles stubbing on the hydra side.
|
|
5
|
-
# It plays well with the block_connection configuration,
|
|
6
|
-
# which raises when you make a request which is not stubbed.
|
|
7
|
-
#
|
|
8
|
-
# @api private
|
|
9
|
-
module Stubbable
|
|
10
|
-
|
|
11
|
-
# Override add in order to check for matching expecations.
|
|
12
|
-
# When an expecation is found, super is not called. Instead a
|
|
13
|
-
# canned response is assigned to the request.
|
|
14
|
-
#
|
|
15
|
-
# @example Add the request.
|
|
16
|
-
# hydra.add(request)
|
|
17
|
-
def add(request)
|
|
18
|
-
if response = Expectation.response_for(request)
|
|
19
|
-
request.execute_headers_callbacks(response)
|
|
20
|
-
request.on_body.each{ |callback| callback.call(response.body, response) }
|
|
21
|
-
request.finish(response)
|
|
22
|
-
else
|
|
23
|
-
super
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
module Typhoeus
|
|
2
|
-
class Request
|
|
3
|
-
|
|
4
|
-
# This module provides a way to hook into before
|
|
5
|
-
# a request runs. This is very powerful
|
|
6
|
-
# and you should be careful because when you accidently
|
|
7
|
-
# return a falsy value the request won't be executed.
|
|
8
|
-
#
|
|
9
|
-
# @api private
|
|
10
|
-
module Before
|
|
11
|
-
|
|
12
|
-
# Overrride run in order to execute callbacks in
|
|
13
|
-
# Typhoeus.before. Will break and return when a
|
|
14
|
-
# callback returns nil or false. Calls super
|
|
15
|
-
# otherwise.
|
|
16
|
-
#
|
|
17
|
-
# @example Run the request.
|
|
18
|
-
# request.run
|
|
19
|
-
def run
|
|
20
|
-
Typhoeus.before.each do |callback|
|
|
21
|
-
value = callback.call(self)
|
|
22
|
-
if value.nil? || value == false || value.is_a?(Response)
|
|
23
|
-
return response
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
super
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
module Typhoeus
|
|
2
|
-
class Request
|
|
3
|
-
|
|
4
|
-
# This module handles the blocked connection request mode on
|
|
5
|
-
# the request side, where only stubbed requests
|
|
6
|
-
# are allowed.
|
|
7
|
-
# Connection blocking needs to be turned on:
|
|
8
|
-
# Typhoeus.configure do |config|
|
|
9
|
-
# config.block_connection = true
|
|
10
|
-
# end
|
|
11
|
-
#
|
|
12
|
-
# When trying to do real requests a NoStub error
|
|
13
|
-
# is raised.
|
|
14
|
-
#
|
|
15
|
-
# @api private
|
|
16
|
-
module BlockConnection
|
|
17
|
-
|
|
18
|
-
# Overrides run in order to check before if block connection
|
|
19
|
-
# is turned on. If thats the case a NoStub error is
|
|
20
|
-
# raised.
|
|
21
|
-
#
|
|
22
|
-
# @example Run request.
|
|
23
|
-
# request.run
|
|
24
|
-
#
|
|
25
|
-
# @raise [Typhoeus::Errors::NoStub] If connection is blocked
|
|
26
|
-
# and no stub defined.
|
|
27
|
-
def run
|
|
28
|
-
if blocked?
|
|
29
|
-
raise Typhoeus::Errors::NoStub.new(self)
|
|
30
|
-
else
|
|
31
|
-
super
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
# Returns wether a request is blocked or not. Takes
|
|
36
|
-
# request.block_connection and Typhoeus::Config.block_connection
|
|
37
|
-
# into consideration.
|
|
38
|
-
#
|
|
39
|
-
# @example Blocked?
|
|
40
|
-
# request.blocked?
|
|
41
|
-
#
|
|
42
|
-
# @return [ Boolean ] True if blocked, false else.
|
|
43
|
-
def blocked?
|
|
44
|
-
if block_connection.nil?
|
|
45
|
-
Typhoeus::Config.block_connection
|
|
46
|
-
else
|
|
47
|
-
block_connection
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
module Typhoeus
|
|
2
|
-
class Request
|
|
3
|
-
module Cacheable
|
|
4
|
-
def response=(response)
|
|
5
|
-
cache.set(self, response) if cacheable? && !response.cached?
|
|
6
|
-
super
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def cacheable?
|
|
10
|
-
cache
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def run
|
|
14
|
-
if response = cached_response
|
|
15
|
-
response.cached = true
|
|
16
|
-
finish(response)
|
|
17
|
-
else
|
|
18
|
-
super
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def cached_response
|
|
23
|
-
cacheable? && cache.get(self)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def cache_ttl
|
|
27
|
-
options[:cache_ttl]
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
private
|
|
31
|
-
|
|
32
|
-
def cache
|
|
33
|
-
return nil if options[:cache] === false
|
|
34
|
-
options[:cache] || Typhoeus::Config.cache
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
module Typhoeus
|
|
2
|
-
class Request
|
|
3
|
-
|
|
4
|
-
# This module handles the GET request memoization
|
|
5
|
-
# on the request side. Memoization needs to be turned
|
|
6
|
-
# on:
|
|
7
|
-
# Typhoeus.configure do |config|
|
|
8
|
-
# config.memoize = true
|
|
9
|
-
# end
|
|
10
|
-
#
|
|
11
|
-
# @api private
|
|
12
|
-
module Memoizable
|
|
13
|
-
|
|
14
|
-
# Override response setter and memoizes response
|
|
15
|
-
# if the request is memoizable.
|
|
16
|
-
#
|
|
17
|
-
# @param [ Response ] response The response to set.
|
|
18
|
-
#
|
|
19
|
-
# @example Set response.
|
|
20
|
-
# request.response = response
|
|
21
|
-
def response=(response)
|
|
22
|
-
hydra.memory[self] = response if memoizable?
|
|
23
|
-
super
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
# Return whether a request is memoizable.
|
|
27
|
-
#
|
|
28
|
-
# @example Is request memoizable?
|
|
29
|
-
# request.memoizable?
|
|
30
|
-
#
|
|
31
|
-
# @return [ Boolean ] Return true if memoizable, false else.
|
|
32
|
-
def memoizable?
|
|
33
|
-
Typhoeus::Config.memoize &&
|
|
34
|
-
(options[:method].nil? || options[:method] == :get)
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
module Typhoeus
|
|
2
|
-
class Request
|
|
3
|
-
|
|
4
|
-
# This module contains everything what is necessary
|
|
5
|
-
# to make a single request.
|
|
6
|
-
module Operations
|
|
7
|
-
|
|
8
|
-
# Run a request.
|
|
9
|
-
#
|
|
10
|
-
# @example Run a request.
|
|
11
|
-
# Typhoeus::Request.new("www.example.com").run
|
|
12
|
-
#
|
|
13
|
-
# @return [ Response ] The response.
|
|
14
|
-
def run
|
|
15
|
-
easy = EasyFactory.new(self).get
|
|
16
|
-
easy.perform
|
|
17
|
-
response
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
# Sets a response, the request on the response
|
|
21
|
-
# and executes the callbacks.
|
|
22
|
-
#
|
|
23
|
-
# @param [Typhoeus::Response] response The response.
|
|
24
|
-
# @param [Boolean] bypass_memoization Wether to bypass
|
|
25
|
-
# memoization or not. Decides how the response is set.
|
|
26
|
-
#
|
|
27
|
-
# @return [Typhoeus::Response] The response.
|
|
28
|
-
def finish(response, bypass_memoization = nil)
|
|
29
|
-
if bypass_memoization
|
|
30
|
-
@response = response
|
|
31
|
-
else
|
|
32
|
-
self.response = response
|
|
33
|
-
end
|
|
34
|
-
self.response.request = self
|
|
35
|
-
execute_callbacks
|
|
36
|
-
response
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
module Typhoeus
|
|
2
|
-
class Request
|
|
3
|
-
|
|
4
|
-
# This module contains logic for having a response
|
|
5
|
-
# getter and setter.
|
|
6
|
-
module Responseable
|
|
7
|
-
|
|
8
|
-
# Set the response.
|
|
9
|
-
#
|
|
10
|
-
# @example Set response.
|
|
11
|
-
# request.response = response
|
|
12
|
-
#
|
|
13
|
-
# @param [ Response ] value The response to set.
|
|
14
|
-
def response=(value)
|
|
15
|
-
@response = value
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
# Return the response.
|
|
19
|
-
#
|
|
20
|
-
# @example Return response.
|
|
21
|
-
# request.response
|
|
22
|
-
#
|
|
23
|
-
# @return [ Response ] The response.
|
|
24
|
-
def response
|
|
25
|
-
@response ||= nil
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
module Typhoeus
|
|
2
|
-
class Request
|
|
3
|
-
|
|
4
|
-
# This module handles stubbing on the request side.
|
|
5
|
-
# It plays well with the block_connection configuration,
|
|
6
|
-
# which raises when you make a request which is not stubbed.
|
|
7
|
-
#
|
|
8
|
-
# @api private
|
|
9
|
-
module Stubbable
|
|
10
|
-
|
|
11
|
-
# Override run in order to check for matching expectations.
|
|
12
|
-
# When an expectation is found, super is not called. Instead a
|
|
13
|
-
# canned response is assigned to the request.
|
|
14
|
-
#
|
|
15
|
-
# @example Run the request.
|
|
16
|
-
# request.run
|
|
17
|
-
#
|
|
18
|
-
# @return [ Response ] The response.
|
|
19
|
-
def run
|
|
20
|
-
if response = Expectation.response_for(self)
|
|
21
|
-
execute_headers_callbacks(response)
|
|
22
|
-
self.on_body.each{ |callback| callback.call(response.body, response) }
|
|
23
|
-
finish(response)
|
|
24
|
-
else
|
|
25
|
-
super
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|