faraday 0.8.11 → 0.9.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.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.document +6 -0
  3. data/CHANGELOG.md +15 -0
  4. data/CONTRIBUTING.md +36 -0
  5. data/Gemfile +10 -3
  6. data/LICENSE.md +1 -1
  7. data/README.md +17 -51
  8. data/Rakefile +2 -18
  9. data/faraday.gemspec +34 -0
  10. data/lib/faraday/adapter/em_http.rb +34 -0
  11. data/lib/faraday/adapter/em_http_ssl_patch.rb +56 -0
  12. data/lib/faraday/adapter/em_synchrony.rb +11 -24
  13. data/lib/faraday/adapter/excon.rb +12 -2
  14. data/lib/faraday/adapter/httpclient.rb +106 -0
  15. data/lib/faraday/adapter/net_http.rb +10 -6
  16. data/lib/faraday/adapter/patron.rb +2 -8
  17. data/lib/faraday/adapter/rack.rb +0 -2
  18. data/lib/faraday/adapter/test.rb +39 -39
  19. data/lib/faraday/adapter/typhoeus.rb +12 -3
  20. data/lib/faraday/adapter.rb +20 -35
  21. data/lib/faraday/autoload.rb +85 -0
  22. data/lib/faraday/connection.rb +232 -125
  23. data/lib/faraday/error.rb +42 -34
  24. data/lib/faraday/options.rb +350 -0
  25. data/lib/faraday/parameters.rb +193 -0
  26. data/lib/faraday/{builder.rb → rack_builder.rb} +79 -22
  27. data/lib/faraday/request/authorization.rb +7 -5
  28. data/lib/faraday/request/basic_authentication.rb +1 -1
  29. data/lib/faraday/request/instrumentation.rb +36 -0
  30. data/lib/faraday/request/multipart.rb +10 -9
  31. data/lib/faraday/request/retry.rb +99 -4
  32. data/lib/faraday/request/token_authentication.rb +2 -2
  33. data/lib/faraday/request/url_encoded.rb +7 -6
  34. data/lib/faraday/request.rb +21 -30
  35. data/lib/faraday/response/logger.rb +4 -4
  36. data/lib/faraday/response/raise_error.rb +4 -2
  37. data/lib/faraday/response.rb +17 -23
  38. data/lib/faraday/utils.rb +81 -71
  39. data/lib/faraday.rb +187 -68
  40. data/script/console +7 -0
  41. data/script/proxy-server +1 -0
  42. data/script/release +6 -3
  43. data/script/test +4 -2
  44. data/test/adapters/em_http_test.rb +6 -1
  45. data/test/adapters/em_synchrony_test.rb +7 -1
  46. data/test/adapters/httpclient_test.rb +21 -0
  47. data/test/adapters/integration.rb +23 -8
  48. data/test/adapters/logger_test.rb +1 -1
  49. data/test/adapters/net_http_persistent_test.rb +10 -1
  50. data/test/adapters/net_http_test.rb +0 -31
  51. data/test/adapters/patron_test.rb +4 -1
  52. data/test/adapters/test_middleware_test.rb +48 -4
  53. data/test/adapters/typhoeus_test.rb +8 -1
  54. data/test/authentication_middleware_test.rb +2 -2
  55. data/test/connection_test.rb +160 -84
  56. data/test/env_test.rb +51 -24
  57. data/test/helper.rb +13 -13
  58. data/test/live_server.rb +8 -0
  59. data/test/middleware/instrumentation_test.rb +88 -0
  60. data/test/middleware/retry_test.rb +88 -35
  61. data/test/middleware_stack_test.rb +13 -12
  62. data/test/options_test.rb +252 -0
  63. data/test/request_middleware_test.rb +11 -1
  64. data/test/response_middleware_test.rb +2 -4
  65. data/test/strawberry.rb +2 -0
  66. data/test/utils_test.rb +34 -6
  67. metadata +71 -11
  68. data/test/parameters_test.rb +0 -24
data/lib/faraday/utils.rb CHANGED
@@ -1,4 +1,5 @@
1
- require 'cgi'
1
+ require 'thread'
2
+ Faraday.require_libs 'parameters'
2
3
 
3
4
  module Faraday
4
5
  module Utils
@@ -6,26 +7,29 @@ module Faraday
6
7
 
7
8
  # Adapted from Rack::Utils::HeaderHash
8
9
  class Headers < ::Hash
9
- def initialize(hash={})
10
+ def self.from(value)
11
+ new(value)
12
+ end
13
+
14
+ def initialize(hash = nil)
10
15
  super()
11
16
  @names = {}
12
- self.update hash
17
+ self.update(hash || {})
13
18
  end
14
19
 
15
- # on dup/clone, we need to duplicate @names hash
16
- def initialize_copy(other)
17
- super
18
- @names = other.names.dup
19
- end
20
+ # need to synchronize concurrent writes to the shared KeyMap
21
+ keymap_mutex = Mutex.new
20
22
 
21
23
  # symbol -> string mapper + cache
22
24
  KeyMap = Hash.new do |map, key|
23
- map[key] = if key.respond_to?(:to_str) then key
25
+ value = if key.respond_to?(:to_str)
26
+ key
24
27
  else
25
28
  key.to_s.split('_'). # :user_agent => %w(user agent)
26
29
  each { |w| w.capitalize! }. # => %w(User Agent)
27
30
  join('-') # => "User-Agent"
28
31
  end
32
+ keymap_mutex.synchronize { map[key] = value }
29
33
  end
30
34
  KeyMap[:etag] = "ETag"
31
35
 
@@ -39,14 +43,20 @@ module Faraday
39
43
  k = (@names[k.downcase] ||= k)
40
44
  # join multiple values with a comma
41
45
  v = v.to_ary.join(', ') if v.respond_to? :to_ary
42
- super k, v
46
+ super(k, v)
47
+ end
48
+
49
+ def fetch(k, *args, &block)
50
+ k = KeyMap[k]
51
+ key = @names.fetch(k.downcase, k)
52
+ super(key, *args, &block)
43
53
  end
44
54
 
45
55
  def delete(k)
46
56
  k = KeyMap[k]
47
57
  if k = @names[k.downcase]
48
58
  @names.delete k.downcase
49
- super k
59
+ super(k)
50
60
  end
51
61
  end
52
62
 
@@ -71,7 +81,6 @@ module Faraday
71
81
 
72
82
  def replace(other)
73
83
  clear
74
- @names.clear
75
84
  self.update other
76
85
  self
77
86
  end
@@ -85,17 +94,13 @@ module Faraday
85
94
  map { |h| h.split(/:\s+/, 2) }.reject { |p| p[0].nil? }. # split key and value, ignore blank lines
86
95
  each { |key, value|
87
96
  # join multiple values with a comma
88
- if self[key] then self[key] << ', ' << value
89
- else self[key] = value
97
+ if self[key]
98
+ self[key] << ', ' << value
99
+ else
100
+ self[key] = value
90
101
  end
91
102
  }
92
103
  end
93
-
94
- protected
95
-
96
- def names
97
- @names
98
- end
99
104
  end
100
105
 
101
106
  # hash with stringified keys
@@ -137,15 +142,15 @@ module Faraday
137
142
  update(other)
138
143
  end
139
144
 
140
- def merge_query(query)
145
+ def merge_query(query, encoder = nil)
141
146
  if query && !query.empty?
142
- update Utils.parse_nested_query(query)
147
+ update((encoder || Utils.default_params_encoder).decode(query))
143
148
  end
144
149
  self
145
150
  end
146
151
 
147
- def to_query
148
- Utils.build_nested_query(self)
152
+ def to_query(encoder = nil)
153
+ (encoder || Utils.default_params_encoder).encode(self)
149
154
  end
150
155
 
151
156
  private
@@ -155,32 +160,12 @@ module Faraday
155
160
  end
156
161
  end
157
162
 
158
- # Copied from Rack
159
163
  def build_query(params)
160
- params.map { |k, v|
161
- if v.class == Array
162
- build_query(v.map { |x| [k, x] })
163
- else
164
- v.nil? ? escape(k) : "#{escape(k)}=#{escape(v)}"
165
- end
166
- }.join("&")
164
+ FlatParamsEncoder.encode(params)
167
165
  end
168
166
 
169
- # Rack's version modified to handle non-String values
170
- def build_nested_query(value, prefix = nil)
171
- case value
172
- when Array
173
- value.map { |v| build_nested_query(v, "#{prefix}%5B%5D") }.join("&")
174
- when Hash
175
- value.map { |k, v|
176
- build_nested_query(v, prefix ? "#{prefix}%5B#{escape(k)}%5D" : escape(k))
177
- }.join("&")
178
- when NilClass
179
- prefix
180
- else
181
- raise ArgumentError, "value must be a Hash" if prefix.nil?
182
- "#{prefix}=#{escape(value)}"
183
- end
167
+ def build_nested_query(params)
168
+ NestedParamsEncoder.encode(params)
184
169
  end
185
170
 
186
171
  ESCAPE_RE = /[^a-zA-Z0-9 .~_-]/
@@ -196,31 +181,20 @@ module Faraday
196
181
  DEFAULT_SEP = /[&;] */n
197
182
 
198
183
  # Adapted from Rack
199
- def parse_query(qs)
200
- params = {}
201
-
202
- (qs || '').split(DEFAULT_SEP).each do |p|
203
- k, v = p.split('=', 2).map { |x| unescape(x) }
184
+ def parse_query(query)
185
+ FlatParamsEncoder.decode(query)
186
+ end
204
187
 
205
- if cur = params[k]
206
- if cur.class == Array then params[k] << v
207
- else params[k] = [cur, v]
208
- end
209
- else
210
- params[k] = v
211
- end
212
- end
213
- params
188
+ def parse_nested_query(query)
189
+ NestedParamsEncoder.decode(query)
214
190
  end
215
191
 
216
- def parse_nested_query(qs)
217
- params = {}
192
+ def default_params_encoder
193
+ @default_params_encoder ||= NestedParamsEncoder
194
+ end
218
195
 
219
- (qs || '').split(DEFAULT_SEP).each do |p|
220
- k, v = p.split('=', 2).map { |s| unescape(s) }
221
- normalize_params(params, k, v)
222
- end
223
- params
196
+ class << self
197
+ attr_writer :default_params_encoder
224
198
  end
225
199
 
226
200
  # Stolen from Rack
@@ -232,7 +206,12 @@ module Faraday
232
206
  return if k.empty?
233
207
 
234
208
  if after == ""
235
- params[k] = v
209
+ if params[k]
210
+ params[k] = Array[params[k]] unless params[k].kind_of?(Array)
211
+ params[k] << v
212
+ else
213
+ params[k] = v
214
+ end
236
215
  elsif after == "[]"
237
216
  params[k] ||= []
238
217
  raise TypeError, "expected Array (got #{params[k].class.name}) for param `#{k}'" unless params[k].is_a?(Array)
@@ -255,9 +234,40 @@ module Faraday
255
234
  return params
256
235
  end
257
236
 
258
- # Receives a URL and returns just the path with the query string sorted.
237
+ # Normalize URI() behavior across Ruby versions
238
+ #
239
+ # url - A String or URI.
240
+ #
241
+ # Returns a parsed URI.
242
+ def URI(url)
243
+ if url.respond_to?(:host)
244
+ url
245
+ elsif url.respond_to?(:to_str)
246
+ default_uri_parser.call(url)
247
+ else
248
+ raise ArgumentError, "bad argument (expected URI object or URI string)"
249
+ end
250
+ end
251
+
252
+ def default_uri_parser
253
+ @default_uri_parser ||= begin
254
+ require 'uri'
255
+ Kernel.method(:URI)
256
+ end
257
+ end
258
+
259
+ def default_uri_parser=(parser)
260
+ @default_uri_parser = if parser.respond_to?(:call) || parser.nil?
261
+ parser
262
+ else
263
+ parser.method(:parse)
264
+ end
265
+ end
266
+
267
+ # Receives a String or URI and returns just the path with the query string sorted.
259
268
  def normalize_path(url)
260
- (url.path != "" ? url.path : "/") +
269
+ url = URI(url)
270
+ (url.path.start_with?('/') ? url.path : '/' + url.path) +
261
271
  (url.query ? "?#{sort_query_params(url.query)}" : "")
262
272
  end
263
273
 
data/lib/faraday.rb CHANGED
@@ -1,25 +1,100 @@
1
+ require 'thread'
2
+ require 'cgi'
3
+ require 'set'
4
+ require 'forwardable'
5
+
6
+ # Public: This is the main namespace for Faraday. You can either use it to
7
+ # create Faraday::Connection objects, or access it directly.
8
+ #
9
+ # Examples
10
+ #
11
+ # Faraday.get "http://faraday.com"
12
+ #
13
+ # conn = Faraday.new "http://faraday.com"
14
+ # conn.get '/'
15
+ #
1
16
  module Faraday
2
- VERSION = "0.8.11"
17
+ VERSION = "0.9.0"
3
18
 
4
19
  class << self
5
- attr_accessor :root_path, :lib_path
6
- attr_accessor :default_adapter
7
- attr_writer :default_connection
20
+ # Public: Gets or sets the root path that Faraday is being loaded from.
21
+ # This is the root from where the libraries are auto-loaded from.
22
+ attr_accessor :root_path
23
+
24
+ # Public: Gets or sets the path that the Faraday libs are loaded from.
25
+ attr_accessor :lib_path
8
26
 
9
- def new(url = nil, options = {})
27
+ # Public: Gets or sets the Symbol key identifying a default Adapter to use
28
+ # for the default Faraday::Connection.
29
+ attr_reader :default_adapter
30
+
31
+ # Public: Sets the default Faraday::Connection for simple scripts that
32
+ # access the Faraday constant directly.
33
+ #
34
+ # Faraday.get "https://faraday.com"
35
+ attr_writer :default_connection
36
+
37
+ # Public: Sets the default options used when calling Faraday#new.
38
+ attr_writer :default_connection_options
39
+
40
+ # Public: Initializes a new Faraday::Connection.
41
+ #
42
+ # url - The optional String base URL to use as a prefix for all
43
+ # requests. Can also be the options Hash.
44
+ # options - The optional Hash used to configure this Faraday::Connection.
45
+ # Any of these values will be set on every request made, unless
46
+ # overridden for a specific request.
47
+ # :url - String base URL.
48
+ # :params - Hash of URI query unencoded key/value pairs.
49
+ # :headers - Hash of unencoded HTTP header key/value pairs.
50
+ # :request - Hash of request options.
51
+ # :ssl - Hash of SSL options.
52
+ # :proxy - Hash of Proxy options.
53
+ #
54
+ # Examples
55
+ #
56
+ # Faraday.new 'http://faraday.com'
57
+ #
58
+ # # http://faraday.com?page=1
59
+ # Faraday.new 'http://faraday.com', :params => {:page => 1}
60
+ #
61
+ # # same
62
+ #
63
+ # Faraday.new :url => 'http://faraday.com',
64
+ # :params => {:page => 1}
65
+ #
66
+ # Returns a Faraday::Connection.
67
+ def new(url = nil, options = nil)
10
68
  block = block_given? ? Proc.new : nil
69
+ options = options ? default_connection_options.merge(options) : default_connection_options.dup
11
70
  Faraday::Connection.new(url, options, &block)
12
71
  end
13
72
 
73
+ # Internal: Requires internal Faraday libraries.
74
+ #
75
+ # *libs - One or more relative String names to Faraday classes.
76
+ #
77
+ # Returns nothing.
14
78
  def require_libs(*libs)
15
79
  libs.each do |lib|
16
80
  require "#{lib_path}/#{lib}"
17
81
  end
18
82
  end
19
83
 
84
+ # Public: Updates default adapter while resetting
85
+ # #default_connection.
86
+ #
87
+ # Returns the new default_adapter.
88
+ def default_adapter=(adapter)
89
+ @default_connection = nil
90
+ @default_adapter = adapter
91
+ end
92
+
20
93
  alias require_lib require_libs
21
94
 
22
95
  private
96
+ # Internal: Proxies method calls on the Faraday constant to
97
+ # #default_connection.
23
98
  def method_missing(name, *args, &block)
24
99
  default_connection.send(name, *args, &block)
25
100
  end
@@ -29,10 +104,20 @@ module Faraday
29
104
  self.lib_path = File.expand_path "../faraday", __FILE__
30
105
  self.default_adapter = :net_http
31
106
 
107
+ # Gets the default connection used for simple scripts.
108
+ #
109
+ # Returns a Faraday::Connection, configured with the #default_adapter.
32
110
  def self.default_connection
33
111
  @default_connection ||= Connection.new
34
112
  end
35
113
 
114
+ # Gets the default connection options used when calling Faraday#new.
115
+ #
116
+ # Returns a Faraday::ConnectionOptions.
117
+ def self.default_connection_options
118
+ @default_connection_options ||= ConnectionOptions.new
119
+ end
120
+
36
121
  if (!defined?(RUBY_ENGINE) || "ruby" == RUBY_ENGINE) && RUBY_VERSION < '1.9'
37
122
  begin
38
123
  require 'system_timer'
@@ -47,103 +132,137 @@ module Faraday
47
132
  Timer = Timeout
48
133
  end
49
134
 
135
+ # Public: Adds the ability for other modules to register and lookup
136
+ # middleware classes.
50
137
  module MiddlewareRegistry
51
- # Internal: Register middleware class(es) on the current module.
138
+ # Public: Register middleware class(es) on the current module.
139
+ #
140
+ # mapping - A Hash mapping Symbol keys to classes. Classes can be expressed
141
+ # as fully qualified constant, or a Proc that will be lazily
142
+ # called to return the former.
143
+ #
144
+ # Examples
145
+ #
146
+ # module Faraday
147
+ # class Whatever
148
+ # # Middleware looked up by :foo returns Faraday::Whatever::Foo.
149
+ # register_middleware :foo => Foo
150
+ #
151
+ # # Middleware looked up by :bar returns Faraday::Whatever.const_get(:Bar)
152
+ # register_middleware :bar => :Bar
52
153
  #
53
- # mapping - A Hash mapping Symbol keys to classes. See
54
- # Faraday.register_middleware for more details.
55
- def register_middleware(mapping)
56
- (@registered_middleware ||= {}).update(mapping)
154
+ # # Middleware looked up by :baz requires 'baz' and returns Faraday::Whatever.const_get(:Baz)
155
+ # register_middleware :baz => [:Baz, 'baz']
156
+ # end
157
+ # end
158
+ #
159
+ # Returns nothing.
160
+ def register_middleware(autoload_path = nil, mapping = nil)
161
+ if mapping.nil?
162
+ mapping = autoload_path
163
+ autoload_path = nil
164
+ end
165
+ middleware_mutex do
166
+ @middleware_autoload_path = autoload_path if autoload_path
167
+ (@registered_middleware ||= {}).update(mapping)
168
+ end
57
169
  end
58
170
 
59
- # Internal: Lookup middleware class with a registered Symbol shortcut.
171
+ # Public: Lookup middleware class with a registered Symbol shortcut.
172
+ #
173
+ # key - The Symbol key for the registered middleware.
174
+ #
175
+ # Examples
176
+ #
177
+ # module Faraday
178
+ # class Whatever
179
+ # register_middleware :foo => Foo
180
+ # end
181
+ # end
182
+ #
183
+ # Faraday::Whatever.lookup_middleware(:foo)
184
+ # # => Faraday::Whatever::Foo
60
185
  #
61
186
  # Returns a middleware Class.
62
187
  def lookup_middleware(key)
63
- unless defined? @registered_middleware and found = @registered_middleware[key]
64
- raise "#{key.inspect} is not registered on #{self}"
65
- end
66
- found = @registered_middleware[key] = found.call if found.is_a? Proc
67
- found.is_a?(Module) ? found : const_get(found)
188
+ load_middleware(key) ||
189
+ raise(Faraday::Error.new("#{key.inspect} is not registered on #{self}"))
68
190
  end
69
- end
70
191
 
71
- module AutoloadHelper
72
- def autoload_all(prefix, options)
73
- if prefix =~ /^faraday(\/|$)/i
74
- prefix = File.join(Faraday.root_path, prefix)
75
- end
76
- options.each do |const_name, path|
77
- autoload const_name, File.join(prefix, path)
192
+ def middleware_mutex(&block)
193
+ @middleware_mutex ||= begin
194
+ require 'monitor'
195
+ Monitor.new
78
196
  end
197
+ @middleware_mutex.synchronize(&block)
79
198
  end
80
199
 
81
- # Loads each autoloaded constant. If thread safety is a concern, wrap
82
- # this in a Mutex.
83
- def load_autoloaded_constants
84
- constants.each do |const|
85
- const_get(const) if autoload?(const)
86
- end
200
+ def fetch_middleware(key)
201
+ defined?(@registered_middleware) && @registered_middleware[key]
87
202
  end
88
203
 
89
- def all_loaded_constants
90
- constants.map { |c| const_get(c) }.
91
- select { |a| a.respond_to?(:loaded?) && a.loaded? }
204
+ def load_middleware(key)
205
+ value = fetch_middleware(key)
206
+ case value
207
+ when Module
208
+ value
209
+ when Symbol, String
210
+ middleware_mutex do
211
+ @registered_middleware[key] = const_get(value)
212
+ end
213
+ when Proc
214
+ middleware_mutex do
215
+ @registered_middleware[key] = value.call
216
+ end
217
+ when Array
218
+ middleware_mutex do
219
+ const, path = value
220
+ if root = @middleware_autoload_path
221
+ path = "#{root}/#{path}"
222
+ end
223
+ require(path)
224
+ @registered_middleware[key] = const
225
+ end
226
+ load_middleware(key)
227
+ end
92
228
  end
93
229
  end
94
230
 
95
- extend AutoloadHelper
96
-
97
- # Public: register middleware classes under a short name.
98
- #
99
- # type - A Symbol specifying the kind of middleware (default: :middleware)
100
- # mapping - A Hash mapping Symbol keys to classes. Classes can be expressed
101
- # as fully qualified constant, or a Proc that will be lazily called
102
- # to return the former.
103
- #
104
- # Examples
105
- #
106
- # Faraday.register_middleware :aloha => MyModule::Aloha
107
- # Faraday.register_middleware :response, :boom => MyModule::Boom
108
- #
109
- # # shortcuts are now available in Builder:
110
- # builder.use :aloha
111
- # builder.response :boom
112
- #
113
- # Returns nothing.
114
- def self.register_middleware type, mapping = nil
115
- type, mapping = :middleware, type if mapping.nil?
116
- component = self.const_get(type.to_s.capitalize)
117
- component.register_middleware(mapping)
231
+ def self.const_missing(name)
232
+ if name.to_sym == :Builder
233
+ warn "Faraday::Builder is now Faraday::RackBuilder."
234
+ const_set name, RackBuilder
235
+ else
236
+ super
237
+ end
118
238
  end
119
239
 
120
- autoload_all "faraday",
121
- :Middleware => 'middleware',
122
- :Builder => 'builder',
123
- :Request => 'request',
124
- :Response => 'response',
125
- :CompositeReadIO => 'upload_io',
126
- :UploadIO => 'upload_io',
127
- :Parts => 'upload_io'
240
+ require_libs "utils", "options", "connection", "rack_builder", "parameters",
241
+ "middleware", "adapter", "request", "response", "upload_io", "error"
128
242
 
129
- require_libs "utils", "connection", "adapter", "error"
243
+ if !ENV["FARADAY_NO_AUTOLOAD"]
244
+ require_lib 'autoload'
245
+ end
130
246
  end
131
247
 
132
-
133
248
  # not pulling in active-support JUST for this method. And I love this method.
134
249
  class Object
135
- # Yields <code>x</code> to the block, and then returns <code>x</code>.
136
250
  # The primary purpose of this method is to "tap into" a method chain,
137
251
  # in order to perform operations on intermediate results within the chain.
138
252
  #
253
+ # Examples
254
+ #
139
255
  # (1..10).tap { |x| puts "original: #{x.inspect}" }.to_a.
140
256
  # tap { |x| puts "array: #{x.inspect}" }.
141
257
  # select { |x| x%2 == 0 }.
142
258
  # tap { |x| puts "evens: #{x.inspect}" }.
143
259
  # map { |x| x*x }.
144
260
  # tap { |x| puts "squares: #{x.inspect}" }
261
+ #
262
+ # Yields self.
263
+ # Returns self.
145
264
  def tap
146
- yield self
265
+ yield(self)
147
266
  self
148
267
  end unless Object.respond_to?(:tap)
149
268
  end
data/script/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env bash
2
+ # Usage: script/console
3
+ # Starts an IRB console with this library loaded.
4
+
5
+ gemspec="$(ls *.gemspec | head -1)"
6
+
7
+ exec bundle exec irb -r "${gemspec%.*}"
data/script/proxy-server CHANGED
@@ -27,6 +27,7 @@ webrick_opts = {
27
27
  if username
28
28
  type, credentials = req.header['proxy-authorization'].first.to_s.split(/\s+/, 2)
29
29
  unless "Basic" == type && match_credentials.call(credentials)
30
+ res['proxy-authenticate'] = %{Basic realm="testing"}
30
31
  raise WEBrick::HTTPStatus::ProxyAuthenticationRequired
31
32
  end
32
33
  end
data/script/release CHANGED
@@ -8,7 +8,10 @@ set -e
8
8
  version="$(script/package | grep Version: | awk '{print $2}')"
9
9
  [ -n "$version" ] || exit 1
10
10
 
11
- git commit -a -m "faraday $version"
12
- git tag "v${version}"
13
- git push origin "v${version}" HEAD
11
+ git commit --allow-empty -a -m "Release $version"
12
+ git tag "v$version"
13
+ git push origin
14
+ git push origin "v$version"
15
+ git push legacy
16
+ git push legacy "v$version"
14
17
  gem push pkg/*-${version}.gem
data/script/test CHANGED
@@ -122,8 +122,10 @@ if [ -n "$(filter_matching "adapters" "${test_files[@]}")" ]; then
122
122
  fi
123
123
  server_pid=$(start_server)
124
124
  proxy_pid=$(start_proxy)
125
- wait_for_server 15 $port || {
125
+ wait_for_server 30 $port || {
126
126
  cat log/test.log
127
+ kill "$server_pid"
128
+ kill "$proxy_pid"
127
129
  exit 1
128
130
  }
129
131
  wait_for_server 5 $proxy_port
@@ -149,7 +151,7 @@ run_test_files() {
149
151
 
150
152
  check_warnings() {
151
153
  # Display Ruby warnings from this project's source files. Abort if any were found.
152
- num="$(grep -F "$PWD" "$warnings" | grep -v "${PWD}/vendor/bundle" | sort | uniq -c | sort -rn | tee /dev/stderr | wc -l)"
154
+ num="$(grep -F "$PWD" "$warnings" | grep -v "${PWD}/bundle" | sort | uniq -c | sort -rn | tee /dev/stderr | wc -l)"
153
155
  rm -f "$warnings"
154
156
  if [ "$num" -gt 0 ]; then
155
157
  echo "FAILED: this test suite doesn't tolerate Ruby syntax warnings!" >&2
@@ -8,8 +8,13 @@ module Adapters
8
8
  Integration.apply(self, :Parallel) do
9
9
  # https://github.com/eventmachine/eventmachine/pull/289
10
10
  undef :test_timeout
11
+
12
+ def test_binds_local_socket
13
+ host = '1.2.3.4'
14
+ conn = create_connection :request => { :bind => { :host => host } }
15
+ assert_equal host, conn.options[:bind][:host]
16
+ end
11
17
  end unless jruby? and ssl_mode?
12
18
  # https://github.com/eventmachine/eventmachine/issues/180
13
-
14
19
  end
15
20
  end
@@ -8,7 +8,13 @@ module Adapters
8
8
  Integration.apply(self, :Parallel) do
9
9
  # https://github.com/eventmachine/eventmachine/pull/289
10
10
  undef :test_timeout
11
- end unless RUBY_VERSION < '1.9' or jruby?
12
11
 
12
+ def test_binds_local_socket
13
+ host = '1.2.3.4'
14
+ conn = create_connection :request => { :bind => { :host => host } }
15
+ #put conn.get('/who-am-i').body
16
+ assert_equal host, conn.options[:bind][:host]
17
+ end
18
+ end unless RUBY_VERSION < '1.9' or jruby?
13
19
  end
14
20
  end
@@ -0,0 +1,21 @@
1
+ require File.expand_path('../integration', __FILE__)
2
+
3
+ module Adapters
4
+ class HttpclientTest < Faraday::TestCase
5
+
6
+ def adapter() :httpclient end
7
+
8
+ Integration.apply(self, :NonParallel) do
9
+ def setup
10
+ require 'httpclient' unless defined?(HTTPClient)
11
+ HTTPClient::NO_PROXY_HOSTS.delete('localhost')
12
+ end
13
+
14
+ def test_binds_local_socket
15
+ host = '1.2.3.4'
16
+ conn = create_connection :request => { :bind => { :host => host } }
17
+ assert_equal host, conn.options[:bind][:host]
18
+ end
19
+ end
20
+ end
21
+ end