typhoeus 0.5.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,21 @@
2
2
 
3
3
  ## Master
4
4
 
5
- [Full Changelog](http://github.com/typhoeus/typhoeus/compare/v0.5.4...master)
5
+ [Full Changelog](http://github.com/typhoeus/typhoeus/compare/v0.6.0...master)
6
+
7
+ ## 0.6
8
+
9
+ [Full Changelog](http://github.com/typhoeus/typhoeus/compare/v0.5.4...v0.6.0)
10
+
11
+ Enhancements:
12
+
13
+ * `Request#url` now also contains the url parameters.
14
+ * Use updated ethon version which provides access to protocols and redir_protocols in response to [libcurl SASL buffer overflow vulnerability](http://curl.haxx.se/docs/adv_20130206.html)
15
+
16
+ Bugfixes:
17
+
18
+ * Corrected ssl options for the faraday adapter.
19
+ * Benchmark is working again.
6
20
 
7
21
  ## 0.5.4
8
22
 
@@ -18,8 +32,8 @@ Enhancements:
18
32
  * Rename parameter `url` to `base_url`. See discussion here: [\#250](https://github.com/typhoeus/typhoeus/issues/250).
19
33
  ([bkimble](https://github.com/bkimble), [\#256](https://github.com/typhoeus/typhoeus/pull/256))
20
34
  * Provide O(1) header access.
21
- * Work around nuby 1.8.7 limitations.
22
- ( [](https://github.com/sshingler), [\#176](https://github.com/typhoeus/typhoeus/pull/176) )
35
+ * Work around ruby 1.8.7 limitations.
36
+ ([Chris Johnson](https://github.com/findchris), [\#227](https://github.com/typhoeus/typhoeus/pull/227) )
23
37
  * Provide symbol access.
24
38
 
25
39
  ## 0.5.3
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Typhoeus [![Build Status](https://secure.travis-ci.org/typhoeus/typhoeus.png)](http://travis-ci.org/typhoeus/typhoeus)
1
+ # Typhoeus [![Build Status](https://secure.travis-ci.org/typhoeus/typhoeus.png)](http://travis-ci.org/typhoeus/typhoeus) [<img src="https://codeclimate.com/github/typhoeus/typhoeus.png" height="13" width="89" />](https://codeclimate.com/github/typhoeus/typhoeus)
2
2
 
3
3
  Like a modern code version of the mythical beast with 100 serpent heads, Typhoeus runs HTTP requests in parallel while cleanly encapsulating handling logic.
4
4
 
@@ -39,9 +39,9 @@ gem "typhoeus"
39
39
 
40
40
  Copyright © 2009-2010 [Paul Dix](http://www.pauldix.net/)
41
41
 
42
- Copyright © 2011 [David Balatero](https://github.com/dbalatero/)
42
+ Copyright © 2011-2012 [David Balatero](https://github.com/dbalatero/)
43
43
 
44
- Copyright © 2012 [Hans Hasselberg](http://www.hans.io)
44
+ Copyright © 2012-2013 [Hans Hasselberg](http://github.com/i0rek/)
45
45
 
46
46
  Permission is hereby granted, free of charge, to any person obtaining a
47
47
  copy of this software and associated documentation files (the "Software"),
@@ -2,9 +2,11 @@ require 'digest/sha2'
2
2
  require 'ethon'
3
3
 
4
4
  require 'typhoeus/config'
5
+ require 'typhoeus/easy_factory'
5
6
  require 'typhoeus/errors'
6
7
  require 'typhoeus/expectation'
7
8
  require 'typhoeus/hydra'
9
+ require 'typhoeus/pool'
8
10
  require 'typhoeus/request'
9
11
  require 'typhoeus/response'
10
12
  require 'typhoeus/version'
@@ -42,7 +44,6 @@ end
42
44
  # @since 0.5.0
43
45
  module Typhoeus
44
46
  extend self
45
- extend Hydra::EasyPool
46
47
  extend Request::Actions
47
48
  extend Request::Callbacks::Types
48
49
 
@@ -98,11 +98,11 @@ module Faraday # :nodoc:
98
98
 
99
99
  ssl_verifyhost = (ssl && ssl.fetch(:verify, true)) ? 2 : 0
100
100
  req.options[:ssl_verifyhost] = ssl_verifyhost
101
- req.options[:sslversion] = ssl[:version] if ssl[:version]
102
- req.options[:sslcert] = ssl[:client_cert_file] if ssl[:client_cert_file]
103
- req.options[:sslkey] = ssl[:client_key_file] if ssl[:client_key_file]
104
- req.options[:cainfo] = ssl[:ca_file] if ssl[:ca_file]
105
- req.options[:capath] = ssl[:ca_path] if ssl[:ca_path]
101
+ req.options[:sslversion] = ssl[:version] if ssl[:version]
102
+ req.options[:sslcert] = ssl[:client_cert] if ssl[:client_cert]
103
+ req.options[:sslkey] = ssl[:client_key] if ssl[:client_key]
104
+ req.options[:cainfo] = ssl[:ca_file] if ssl[:ca_file]
105
+ req.options[:capath] = ssl[:ca_path] if ssl[:ca_path]
106
106
  end
107
107
 
108
108
  def configure_proxy(req, env)
@@ -0,0 +1,115 @@
1
+ module Typhoeus
2
+
3
+ # This is a Factory for easies to be used in the hydra.
4
+ # Before an easy is ready to be added to a multi the
5
+ # on_complete callback to be set.
6
+ # This is done by this class.
7
+ #
8
+ # @api private
9
+ class EasyFactory
10
+
11
+ # Returns the request provided.
12
+ #
13
+ # @return [ Typhoeus::Request ]
14
+ attr_reader :request
15
+
16
+ # Returns the hydra provided.
17
+ #
18
+ # @return [ Typhoeus::Hydra ]
19
+ attr_reader :hydra
20
+
21
+ # Create an easy factory.
22
+ #
23
+ # @example Create easy factory.
24
+ # Typhoeus::Hydra::EasyFactory.new(request, hydra)
25
+ #
26
+ # @param [ Request ] request The request to build an easy for.
27
+ # @param [ Hydra ] hydra The hydra to build an easy for.
28
+ def initialize(request, hydra = nil)
29
+ @request = request
30
+ @hydra = hydra
31
+ end
32
+
33
+ # Return the easy in question.
34
+ #
35
+ # @example Return easy.
36
+ # easy_factory.easy
37
+ #
38
+ # @return [ Ethon::Easy ] The easy.
39
+ def easy
40
+ @easy ||= Typhoeus::Pool.get
41
+ end
42
+
43
+ # Fabricated easy.
44
+ #
45
+ # @example Prepared easy.
46
+ # easy_factory.get
47
+ #
48
+ # @return [ Ethon::Easy ] The easy.
49
+ def get
50
+ begin
51
+ easy.http_request(
52
+ request.base_url,
53
+ request.options.fetch(:method, :get),
54
+ request.options.reject{|k,_| k==:method}
55
+ )
56
+ rescue Ethon::Errors::InvalidOption => e
57
+ help = provide_help(e.message.match(/:\s(\w+)/)[1])
58
+ raise $!, "#{$!}#{help}", $!.backtrace
59
+ end
60
+ set_callback
61
+ easy
62
+ end
63
+
64
+ private
65
+
66
+ # Sets on_complete callback on easy in order to be able to
67
+ # track progress.
68
+ #
69
+ # @example Set callback.
70
+ # easy_factory.set_callback
71
+ #
72
+ # @return [ Ethon::Easy ] The easy.
73
+ def set_callback
74
+ easy.on_complete do |easy|
75
+ request.finish(Response.new(easy.to_hash))
76
+ Typhoeus::Pool.release(easy)
77
+ if hydra && !hydra.queued_requests.empty?
78
+ hydra.add(hydra.queued_requests.shift)
79
+ end
80
+ end
81
+ end
82
+
83
+ def provide_help(option)
84
+ renamed = {
85
+ :auth_method => :httpauth,
86
+ :connect_timeout => :connecttimeout,
87
+ :disable_ssl_host_verification => :ssl_verifyhost,
88
+ :disable_ssl_peer_verification => :ssl_verifypeer,
89
+ :encoding => :accept_encoding,
90
+ :follow_location => :followlocation,
91
+ :max_redirects => :maxredirs,
92
+ :password => :userpwd,
93
+ :proxy_auth_method => :proxyauth,
94
+ :proxy_password => :proxyuserpwd,
95
+ :proxy_type => :proxytype,
96
+ :proxy_username => :proxyuserpwd,
97
+ :ssl_cacert => :cainfo,
98
+ :ssl_capath => :capath,
99
+ :ssl_cert => :sslcert,
100
+ :ssl_cert_type => :sslcerttype,
101
+ :ssl_key => :sslkey,
102
+ :ssl_key_password => :keypasswd,
103
+ :ssl_key_type => :sslkeytype,
104
+ :ssl_version => :sslversion,
105
+ :username => :userpwd
106
+ }
107
+ removed = [:cache_key_basis, :cache_timout, :user_agent]
108
+ if new_option = renamed[option.to_sym]
109
+ "\nPlease try #{new_option} instead of #{option}." if new_option
110
+ elsif removed.include?(option.to_sym)
111
+ "\nThe option #{option} was removed."
112
+ end
113
+ end
114
+ end
115
+ end
@@ -63,12 +63,12 @@ module Typhoeus
63
63
  end
64
64
  end
65
65
 
66
- # Creates an expactation.
66
+ # Creates an expectation.
67
67
  #
68
- # @example Create expactation.
68
+ # @example Create expectation.
69
69
  # Typhoeus::Expectation.new(base_url)
70
70
  #
71
- # @return [ Expectation ] The created expactation.
71
+ # @return [ Expectation ] The created expectation.
72
72
  #
73
73
  # @api private
74
74
  def initialize(base_url, options = {})
@@ -78,11 +78,11 @@ module Typhoeus
78
78
  @from = nil
79
79
  end
80
80
 
81
- # Set from value to mark an expecation. Useful for
81
+ # Set from value to mark an expectaion. Useful for
82
82
  # other libraries, eg. webmock.
83
83
  #
84
- # @example Mark expecation.
85
- # expecation.from(:webmock)
84
+ # @example Mark expectation.
85
+ # expectation.from(:webmock)
86
86
  #
87
87
  # @param [ String ] value Value to set.
88
88
  #
@@ -95,7 +95,7 @@ module Typhoeus
95
95
  end
96
96
 
97
97
  # Specify what should be returned,
98
- # when this expactation is hit.
98
+ # when this expectation is hit.
99
99
  #
100
100
  # @example Add response.
101
101
  # expectation.and_return(response)
@@ -1,8 +1,6 @@
1
1
  require 'typhoeus/hydra/addable'
2
2
  require 'typhoeus/hydra/before'
3
3
  require 'typhoeus/hydra/block_connection'
4
- require 'typhoeus/hydra/easy_factory'
5
- require 'typhoeus/hydra/easy_pool'
6
4
  require 'typhoeus/hydra/memoizable'
7
5
  require 'typhoeus/hydra/queueable'
8
6
  require 'typhoeus/hydra/runnable'
@@ -40,7 +38,6 @@ module Typhoeus
40
38
  # @note Callbacks are going to delay the request
41
39
  # execution.
42
40
  class Hydra
43
- include Hydra::EasyPool
44
41
  include Hydra::Addable
45
42
  include Hydra::Runnable
46
43
  include Hydra::Memoizable
@@ -16,7 +16,7 @@ module Typhoeus
16
16
  #
17
17
  # @return [ void ]
18
18
  def add(request)
19
- multi.add(Hydra::EasyFactory.new(request, self).get)
19
+ multi.add(EasyFactory.new(request, self).get)
20
20
  end
21
21
  end
22
22
  end
@@ -0,0 +1,51 @@
1
+ module Typhoeus
2
+
3
+ # The easy pool stores already initialized
4
+ # easy handles for future use. This is useful
5
+ # because creating them is quite expensive.
6
+ #
7
+ # @api private
8
+ module Pool
9
+ extend self
10
+
11
+ # Return the easy pool.
12
+ #
13
+ # @example Return easy pool.
14
+ # hydra.easy_pool
15
+ #
16
+ # @return [ Array<Ethon::Easy> ] The easy pool.
17
+ def easies
18
+ @easies ||= []
19
+ end
20
+
21
+ # Releases easy into pool. The easy handle is
22
+ # resetted before it gets back in.
23
+ #
24
+ # @example Release easy.
25
+ # hydra.release_easy(easy)
26
+ def release(easy)
27
+ easy.reset
28
+ easies << easy
29
+ end
30
+
31
+ # Return an easy from pool.
32
+ #
33
+ # @example Return easy.
34
+ # hydra.get_easy
35
+ #
36
+ # @return [ Ethon::Easy ] The easy.
37
+ def get
38
+ easies.pop || Ethon::Easy.new
39
+ end
40
+
41
+ def clear
42
+ easies.clear
43
+ end
44
+
45
+ def with_easy(&block)
46
+ easy = get
47
+ yield easy
48
+ release easy
49
+ end
50
+ end
51
+ end
@@ -111,9 +111,17 @@ module Typhoeus
111
111
 
112
112
  set_defaults
113
113
  end
114
-
114
+
115
+ # Return the url.
116
+ # In contrast to base_url which returns the value you specified, url returns
117
+ # the full url including the parameters.
118
+ #
119
+ # @example Get the url.
120
+ # request.url
121
+ #
122
+ # @since 0.5.5
115
123
  def url
116
- base_url
124
+ EasyFactory.new(self).get.url
117
125
  end
118
126
 
119
127
  # Returns wether other is equal to self.
@@ -20,7 +20,7 @@ module Typhoeus
20
20
  Typhoeus.before.each do |callback|
21
21
  value = callback.call(self)
22
22
  if value.nil? || value == false || value.is_a?(Response)
23
- return value
23
+ return response
24
24
  end
25
25
  end
26
26
  super
@@ -12,20 +12,8 @@ module Typhoeus
12
12
  #
13
13
  # @return [ Response ] The response.
14
14
  def run
15
- easy = Typhoeus.get_easy
16
- begin
17
- easy.http_request(
18
- base_url,
19
- options.fetch(:method, :get),
20
- options.reject{|k,_| k==:method}
21
- )
22
- rescue Ethon::Errors::InvalidOption => e
23
- help = provide_help(e.message.match(/:\s(\w+)/)[1])
24
- raise $!, "#{$!}#{help}", $!.backtrace
25
- end
15
+ easy = EasyFactory.new(self).get
26
16
  easy.perform
27
- finish(Response.new(easy.to_hash))
28
- Typhoeus.release_easy(easy)
29
17
  response
30
18
  end
31
19
 
@@ -47,40 +35,6 @@ module Typhoeus
47
35
  execute_callbacks
48
36
  response
49
37
  end
50
-
51
- private
52
-
53
- def provide_help(option)
54
- renamed = {
55
- :auth_method => :httpauth,
56
- :connect_timeout => :connecttimeout,
57
- :disable_ssl_host_verification => :ssl_verifyhost,
58
- :disable_ssl_peer_verification => :ssl_verifypeer,
59
- :encoding => :accept_encoding,
60
- :follow_location => :followlocation,
61
- :max_redirects => :maxredirs,
62
- :password => :userpwd,
63
- :proxy_auth_method => :proxyauth,
64
- :proxy_password => :proxyuserpwd,
65
- :proxy_type => :proxytype,
66
- :proxy_username => :proxyuserpwd,
67
- :ssl_cacert => :cainfo,
68
- :ssl_capath => :capath,
69
- :ssl_cert => :sslcert,
70
- :ssl_cert_type => :sslcerttype,
71
- :ssl_key => :sslkey,
72
- :ssl_key_password => :keypasswd,
73
- :ssl_key_type => :sslkeytype,
74
- :ssl_version => :sslversion,
75
- :username => :userpwd
76
- }
77
- removed = [:cache_key_basis, :cache_timout, :user_agent]
78
- if new_option = renamed[option.to_sym]
79
- "\nPlease try #{new_option} instead of #{option}." if new_option
80
- elsif removed.include?(option.to_sym)
81
- "\nThe option #{option} was removed."
82
- end
83
- end
84
38
  end
85
39
  end
86
40
  end
@@ -1,5 +1,5 @@
1
1
  module Typhoeus
2
2
 
3
3
  # The current Typhoeus version.
4
- VERSION = '0.5.4'
4
+ VERSION = '0.6.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typhoeus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-01-11 00:00:00.000000000 Z
14
+ date: 2013-02-11 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: ethon
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ~>
22
22
  - !ruby/object:Gem::Version
23
- version: 0.5.7
23
+ version: 0.5.8
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
@@ -28,7 +28,7 @@ dependencies:
28
28
  requirements:
29
29
  - - ~>
30
30
  - !ruby/object:Gem::Version
31
- version: 0.5.7
31
+ version: 0.5.8
32
32
  description: Like a modern code version of the mythical beast with 100 serpent heads,
33
33
  Typhoeus runs HTTP requests in parallel while cleanly encapsulating handling logic.
34
34
  email:
@@ -42,6 +42,7 @@ files:
42
42
  - lib/rack/typhoeus.rb
43
43
  - lib/typhoeus/adapters/faraday.rb
44
44
  - lib/typhoeus/config.rb
45
+ - lib/typhoeus/easy_factory.rb
45
46
  - lib/typhoeus/errors/no_stub.rb
46
47
  - lib/typhoeus/errors/typhoeus_error.rb
47
48
  - lib/typhoeus/errors.rb
@@ -49,13 +50,12 @@ files:
49
50
  - lib/typhoeus/hydra/addable.rb
50
51
  - lib/typhoeus/hydra/before.rb
51
52
  - lib/typhoeus/hydra/block_connection.rb
52
- - lib/typhoeus/hydra/easy_factory.rb
53
- - lib/typhoeus/hydra/easy_pool.rb
54
53
  - lib/typhoeus/hydra/memoizable.rb
55
54
  - lib/typhoeus/hydra/queueable.rb
56
55
  - lib/typhoeus/hydra/runnable.rb
57
56
  - lib/typhoeus/hydra/stubbable.rb
58
57
  - lib/typhoeus/hydra.rb
58
+ - lib/typhoeus/pool.rb
59
59
  - lib/typhoeus/railtie.rb
60
60
  - lib/typhoeus/request/actions.rb
61
61
  - lib/typhoeus/request/before.rb
@@ -92,7 +92,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
92
  version: '0'
93
93
  segments:
94
94
  - 0
95
- hash: -4558354049498247324
95
+ hash: -2675130828184465692
96
96
  required_rubygems_version: !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements:
@@ -1,78 +0,0 @@
1
- module Typhoeus
2
- class Hydra
3
-
4
- # This is a Factory for easies to be used in the hydra.
5
- # Before an easy is ready to be added to a multi the
6
- # on_complete callback to be set.
7
- # This is done by this class.
8
- #
9
- # @api private
10
- class EasyFactory
11
-
12
- # Returns the request provided.
13
- #
14
- # @return [ Typhoeus::Request ]
15
- attr_reader :request
16
-
17
- # Returns the hydra provided.
18
- #
19
- # @return [ Typhoeus::Hydra ]
20
- attr_reader :hydra
21
-
22
- # Create an easy factory.
23
- #
24
- # @example Create easy factory.
25
- # Typhoeus::Hydra::EasyFactory.new(request, hydra)
26
- #
27
- # @param [ Request ] request The request to build an easy for.
28
- # @param [ Hydra ] hydra The hydra to build an easy for.
29
- def initialize(request, hydra)
30
- @request = request
31
- @hydra = hydra
32
- end
33
-
34
- # Return the easy in question.
35
- #
36
- # @example Return easy.
37
- # easy_factory.easy
38
- #
39
- # @return [ Ethon::Easy ] The easy.
40
- def easy
41
- @easy ||= hydra.get_easy
42
- end
43
-
44
- # Fabricated easy.
45
- #
46
- # @example Prepared easy.
47
- # easy_factory.get
48
- #
49
- # @return [ Ethon::Easy ] The easy.
50
- def get
51
- easy.http_request(
52
- request.base_url,
53
- request.options.fetch(:method, :get),
54
- request.options.reject{|k,_| k==:method}
55
- )
56
- set_callback
57
- easy
58
- end
59
-
60
- private
61
-
62
- # Sets on_complete callback on easy in order to be able to
63
- # track progress.
64
- #
65
- # @example Set callback.
66
- # easy_factory.set_callback
67
- #
68
- # @return [ Ethon::Easy ] The easy.
69
- def set_callback
70
- easy.on_complete do |easy|
71
- request.finish(Response.new(easy.to_hash))
72
- hydra.release_easy(easy)
73
- hydra.add(hydra.queued_requests.shift) unless hydra.queued_requests.empty?
74
- end
75
- end
76
- end
77
- end
78
- end
@@ -1,42 +0,0 @@
1
- module Typhoeus
2
- class Hydra
3
-
4
- # The easy pool stores already initialized
5
- # easy handles for future use. This is useful
6
- # because creating them is quite expensive.
7
- #
8
- # @api private
9
- module EasyPool
10
-
11
- # Return the easy pool.
12
- #
13
- # @example Return easy pool.
14
- # hydra.easy_pool
15
- #
16
- # @return [ Array<Ethon::Easy> ] The easy pool.
17
- def easy_pool
18
- @easy_pool ||= []
19
- end
20
-
21
- # Releases easy into pool. The easy handle is
22
- # resetted before it gets back in.
23
- #
24
- # @example Release easy.
25
- # hydra.release_easy(easy)
26
- def release_easy(easy)
27
- easy.reset
28
- easy_pool << easy
29
- end
30
-
31
- # Return an easy from pool.
32
- #
33
- # @example Return easy.
34
- # hydra.get_easy
35
- #
36
- # @return [ Ethon::Easy ] The easy.
37
- def get_easy
38
- easy_pool.pop || Ethon::Easy.new
39
- end
40
- end
41
- end
42
- end