ethon 0.5.11 → 0.5.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,25 @@
2
2
 
3
3
  ## Master
4
4
 
5
- [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.5.11...master)
5
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.5.12...master)
6
+
7
+ ## 0.5.12
8
+
9
+ [Full Changelog](https://github.com/typhoeus/ethon/compare/v0.5.11...v0.5.12)
10
+
11
+ Enhancements:
12
+
13
+ * Performance optimizations.
14
+ ([Kyle Oppenheim](https://github.com/koppenheim) and [Richie Vos](https://github.com/richievos), [\#48](https://github.com/typhoeus/ethon/pull/48))
15
+ * Reuse memory pointer.
16
+ ([Richie Vos](https://github.com/richievos), [\#49](https://github.com/typhoeus/ethon/pull/49))
17
+
18
+ Bugfixes:
19
+
20
+ * Fix windows install.
21
+ ([Derik Olsson](https://github.com/derikolsson), [\#47](https://github.com/typhoeus/ethon/pull/47))
22
+ * Handle urls that already contain query params.
23
+ ([Turner King](https://github.com/turnerking ), [\#45](https://github.com/typhoeus/ethon/pull/45))
6
24
 
7
25
  ## 0.5.11
8
26
 
@@ -16,12 +34,12 @@ Enhancements:
16
34
  * Relax ffi requirements.
17
35
  ([voxik](https://github.com/voxik), [\#40](https://github.com/typhoeus/ethon/pull/40))
18
36
  * Various documentation improvements.
19
- ([craiglittle](https://github.com/craiglittle))
37
+ ([Craig Little](https://github.com/craiglittle))
20
38
 
21
39
  Bugfixes:
22
40
 
23
41
  * Fix the memory leaks.
24
- ([richievos](https://github.com/richievos), [\#45](https://github.com/typhoeus/ethon/pull/45))
42
+ ([Richie Vos](https://github.com/richievos), [\#45](https://github.com/typhoeus/ethon/pull/45))
25
43
 
26
44
  ## 0.5.10
27
45
 
@@ -30,7 +48,7 @@ Bugfixes:
30
48
  Enhancements:
31
49
 
32
50
  * Allow custom requests.
33
- ([nate](https://github.com/nate), [\#36](https://github.com/typhoeus/ethon/pull/36))
51
+ ([Nathan Sutton](https://github.com/nate), [\#36](https://github.com/typhoeus/ethon/pull/36))
34
52
  * Use updated version of FFI.
35
53
 
36
54
  Bugfixes:
data/Gemfile CHANGED
@@ -6,7 +6,7 @@ gem "rake"
6
6
  group :development, :test do
7
7
  gem "rspec", "~> 2.11"
8
8
 
9
- gem "sinatra", "~> 1.3"
9
+ gem "sinatra", git: "https://github.com/sinatra/sinatra.git"
10
10
  gem "json"
11
11
 
12
12
  unless ENV["CI"]
@@ -35,12 +35,6 @@ module Ethon
35
35
  !(RbConfig::CONFIG['host_os'] !~ /mingw|mswin|bccwin/)
36
36
  end
37
37
 
38
- if Curl.windows?
39
- ffi_lib 'ws2_32'
40
- else
41
- ffi_lib ::FFI::Library::LIBC
42
- end
43
-
44
38
  require 'ethon/curls/constants'
45
39
  require 'ethon/curls/settings'
46
40
  require 'ethon/curls/classes'
@@ -51,6 +51,12 @@ module Ethon
51
51
  base.attach_function :slist_free_all, :curl_slist_free_all, [:pointer], :void
52
52
  base.instance_variable_set(:@blocking, true)
53
53
 
54
+ if Curl.windows?
55
+ base.ffi_lib 'ws2_32'
56
+ else
57
+ base.ffi_lib ::FFI::Library::LIBC
58
+ end
59
+
54
60
  base.attach_function :select, [:int, Curl::FDSet.ptr, Curl::FDSet.ptr, Curl::FDSet.ptr, Curl::Timeval.ptr], :int
55
61
  end
56
62
  end
@@ -229,10 +229,11 @@ module Ethon
229
229
  # @see initialize
230
230
  def set_attributes(options)
231
231
  options.each_pair do |key, value|
232
- unless respond_to?("#{key}=")
232
+ method = "#{key}="
233
+ unless respond_to?(method)
233
234
  raise Errors::InvalidOption.new(key)
234
235
  end
235
- method("#{key}=").call(value)
236
+ send(method, value)
236
237
  end
237
238
  end
238
239
 
@@ -244,7 +245,7 @@ module Ethon
244
245
  def reset
245
246
  @url = nil
246
247
  @hash = nil
247
- @on_complete = []
248
+ @on_complete = nil
248
249
  Curl.easy_reset(handle)
249
250
  set_callbacks
250
251
  end
@@ -278,7 +279,7 @@ module Ethon
278
279
  :response_body => response_body
279
280
  }
280
281
  Easy::Informations::AVAILABLE_INFORMATIONS.keys.each do |info|
281
- @hash[info] = method(info).call
282
+ @hash[info] = send(info)
282
283
  end
283
284
  @hash
284
285
  end
@@ -87,7 +87,9 @@ module Ethon
87
87
  # @param [ Easy ] easy The easy to setup.
88
88
  def set_params(easy)
89
89
  params.escape = true
90
- easy.url = "#{url}?#{params.to_s}"
90
+ base_url, base_params = url.split("?")
91
+ base_params += "&" if base_params
92
+ easy.url = "#{base_url}?#{base_params}#{params.to_s}"
91
93
  end
92
94
 
93
95
  # Setup request with form.
@@ -66,9 +66,7 @@ module Ethon
66
66
  }
67
67
 
68
68
  AVAILABLE_INFORMATIONS.each do |name, type|
69
- define_method(name) do
70
- Curl.method("get_info_#{type}").call(name, handle)
71
- end
69
+ eval %Q|def #{name}; Curl.send(:get_info_#{type}, :#{name}, handle); end|
72
70
  end
73
71
 
74
72
  # Returns this curl version supports zlib.
@@ -22,7 +22,7 @@ module Ethon
22
22
  def perform
23
23
  @return_code = Curl.easy_perform(handle)
24
24
  complete
25
- Ethon.logger.debug("ETHON: performed #{self.log_inspect}")
25
+ Ethon.logger.debug { "ETHON: performed #{self.log_inspect}" }
26
26
  @return_code
27
27
  end
28
28
 
@@ -522,11 +522,29 @@ module Ethon
522
522
  Curl.set_option(:postfieldsize, value_for(value, :int), handle)
523
523
  end
524
524
 
525
+ # Pass a bitmask to control how libcurl acts on redirects after
526
+ # POSTs that get a 301, 302 or 303 response back. A parameter
527
+ # with bit 0 set (value CURL_REDIR_POST_301) tells the library
528
+ # to respect RFC 2616/10.3.2 and not convert POST requests into
529
+ # GET requests when following a 301 redirection. Setting bit 1
530
+ # (value CURL_REDIR_POST_302) makes libcurl maintain the request
531
+ # method after a 302 redirect whilst setting bit 2 (value
532
+ # CURL_REDIR_POST_303) makes libcurl maintain the request method
533
+ # after a 303 redirect. The value CURL_REDIR_POST_ALL is a
534
+ # convenience define that sets all three bits.
535
+ #
536
+ # The non-RFC behaviour is ubiquitous in web browsers, so the
537
+ # library does the conversion by default to maintain
538
+ # consistency. However, a server may require a POST to remain a
539
+ # POST after such a redirection. This option is meaningful only
540
+ # when setting CURLOPT_FOLLOWLOCATION. (Added in 7.17.1) (This
541
+ # option was known as CURLOPT_POST301 up to 7.19.0 as it only
542
+ # supported the 301 then)
543
+ #
544
+ # @example Set postredir option.
545
+ # easy.postredir = :post_all
525
546
  #
526
- # @example Set protocols option.
527
- # easy.protocols = :http
528
- #
529
- # @param [ Symbol ] value The value or array of values to set.
547
+ # @param [ Symbol ] value The value to set.
530
548
  #
531
549
  # @return [ void ]
532
550
  def postredir=(value)
@@ -27,12 +27,14 @@ module Ethon
27
27
  #
28
28
  # @return [ String ] The string representation.
29
29
  def to_s
30
- query_pairs.map{ |pair|
30
+ @to_s ||= query_pairs.map{ |pair|
31
31
  return pair if pair.is_a?(String)
32
32
 
33
- pair.map{ |e|
34
- escape && @easy ? @easy.escape(e.to_s) : e
35
- }.join("=")
33
+ if escape && @easy
34
+ pair.map{ |e| @easy.escape(e.to_s) }.join("=")
35
+ else
36
+ pair.join("=")
37
+ end
36
38
  }.join('&')
37
39
  end
38
40
 
@@ -59,21 +61,7 @@ module Ethon
59
61
  return [hash] if hash.is_a?(String)
60
62
 
61
63
  pairs = []
62
- recursive = Proc.new do |h, prefix|
63
- case h
64
- when Hash
65
- h.each_pair do |k,v|
66
- key = prefix == '' ? k : "#{prefix}[#{k}]"
67
- pairs_for(v, key, pairs, recursive)
68
- end
69
- when Array
70
- h.each_with_index do |v, i|
71
- key = "#{prefix}[#{i}]"
72
- pairs_for(v, key, pairs, recursive)
73
- end
74
- end
75
- end
76
- recursive.call(hash, '')
64
+ recursively_generate_pairs(hash, nil, pairs)
77
65
  pairs
78
66
  end
79
67
 
@@ -97,12 +85,27 @@ module Ethon
97
85
 
98
86
  private
99
87
 
100
- def pairs_for(v, key, pairs, recursive)
88
+ def recursively_generate_pairs(h, prefix, pairs)
89
+ case h
90
+ when Hash
91
+ h.each_pair do |k,v|
92
+ key = prefix.nil? ? k : "#{prefix}[#{k}]"
93
+ pairs_for(v, key, pairs)
94
+ end
95
+ when Array
96
+ h.each_with_index do |v, i|
97
+ key = "#{prefix}[#{i}]"
98
+ pairs_for(v, key, pairs)
99
+ end
100
+ end
101
+ end
102
+
103
+ def pairs_for(v, key, pairs)
101
104
  case v
102
105
  when Hash
103
- recursive.call(v, key)
106
+ recursively_generate_pairs(v, key, pairs)
104
107
  when Array
105
- recursive.call(v, key)
108
+ recursively_generate_pairs(v, key, pairs)
106
109
  when File, Tempfile
107
110
  pairs << [Util.escape_zero_byte(key), file_info(v)]
108
111
  else
@@ -40,7 +40,7 @@ module Ethon
40
40
  # request.complete
41
41
  def complete
42
42
  if defined?(@on_complete)
43
- @on_complete.map{ |callback| callback.call(self) }
43
+ @on_complete.each{ |callback| callback.call(self) }
44
44
  end
45
45
  end
46
46
  end
@@ -2,6 +2,9 @@ module Ethon
2
2
  class Multi # :nodoc
3
3
  # This module contains logic to run a multi.
4
4
  module Operations
5
+ STARTED_MULTI = "ETHON: started MULTI"
6
+ PERFORMED_MULTI = "ETHON: performed MULTI"
7
+
5
8
  # Return the multi handle. Inititialize multi handle,
6
9
  # in case it didn't happened already.
7
10
  #
@@ -35,7 +38,7 @@ module Ethon
35
38
  # @example Perform multi.
36
39
  # multi.perform
37
40
  def perform
38
- Ethon.logger.debug("ETHON: started MULTI")
41
+ Ethon.logger.debug(STARTED_MULTI)
39
42
  while ongoing?
40
43
  run
41
44
  timeout = get_timeout
@@ -43,7 +46,7 @@ module Ethon
43
46
  reset_fds
44
47
  set_fds(timeout)
45
48
  end
46
- Ethon.logger.debug("ETHON: performed MULTI")
49
+ Ethon.logger.debug(PERFORMED_MULTI)
47
50
  nil
48
51
  end
49
52
 
@@ -140,7 +143,7 @@ module Ethon
140
143
  next if msg[:code] != :done
141
144
  easy = easy_handles.find{ |e| e.handle == msg[:easy_handle] }
142
145
  easy.return_code = msg[:data][:code]
143
- Ethon.logger.debug("ETHON: performed #{easy.log_inspect}")
146
+ Ethon.logger.debug { "ETHON: performed #{easy.log_inspect}" }
144
147
  delete(easy)
145
148
  easy.complete
146
149
  end
@@ -153,7 +156,8 @@ module Ethon
153
156
  #
154
157
  # @return [ void ]
155
158
  def run
156
- begin code = trigger end while code == :call_multi_perform
159
+ running_count_pointer = FFI::MemoryPointer.new(:int)
160
+ begin code = trigger(running_count_pointer) end while code == :call_multi_perform
157
161
  check
158
162
  end
159
163
 
@@ -163,10 +167,9 @@ module Ethon
163
167
  # multi.trigger
164
168
  #
165
169
  # @return [ Symbol ] The Curl.multi_perform return code.
166
- def trigger
167
- running_count = FFI::MemoryPointer.new(:int)
168
- code = Curl.multi_perform(handle, running_count)
169
- @running_count = running_count.read_int
170
+ def trigger(running_count_pointer)
171
+ code = Curl.multi_perform(handle, running_count_pointer)
172
+ @running_count = running_count_pointer.read_int
170
173
  code
171
174
  end
172
175
 
@@ -1,5 +1,5 @@
1
1
  module Ethon
2
2
 
3
3
  # Ethon version.
4
- VERSION = '0.5.11'
4
+ VERSION = '0.5.12'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ethon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.11
4
+ version: 0.5.12
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-09 00:00:00.000000000 Z
12
+ date: 2013-04-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
@@ -126,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
126
  version: '0'
127
127
  segments:
128
128
  - 0
129
- hash: 3434979125068377231
129
+ hash: 2640646266244561120
130
130
  required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  none: false
132
132
  requirements: