faraday 0.12.2 → 0.13.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 515b1bc445a69d6ccdbb95b042750cd08962053a
4
- data.tar.gz: 504c63a2fb5c1bb6eec8b8cf9d930bd966984be2
3
+ metadata.gz: 35295b9b568c043b6a43f3074c811fb901f16476
4
+ data.tar.gz: 379f16be0a414f7d18b3012a83a204c53de0ac29
5
5
  SHA512:
6
- metadata.gz: 5da384774bb02aae523a55d2f383ae4f0804757eabd1a398eca2998f6c6279391cb48c39e99d7948d63b4a71953ef98e31eb7e5dad57af5b615c9af007e8e870
7
- data.tar.gz: 63f74afdb08b2232af31ceb76309466f30a3fc4e4d9edbb2e67d4ecac94e432591edc0932fb32ad3945af261b49c7fc6663e06bc8fbfef1f24a9ce60418cc76a
6
+ metadata.gz: 7273cd3b89bea73f73ad25804cd275035db74ceec823102816a6ba9710f4dbb43e9a5a5aa4c6367cdfe33a6eb029f3634bfedbe49f9f427a01bae3a008bc70ab
7
+ data.tar.gz: a3e0d40b1c36a8d03d39f46f0cccc76df5d6554f76a2c1179ae8ff19e49d8ef7f69e9ff0cd6d15a221370f168ca7a1cc47d430a1841135f91fdb76ceed219d96
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/faraday.svg)](https://rubygems.org/gems/faraday)
4
4
  [![Build Status](https://travis-ci.org/lostisland/faraday.svg)](https://travis-ci.org/lostisland/faraday)
5
+ [![Coverage Status](https://coveralls.io/repos/github/lostisland/faraday/badge.svg?branch=master)](https://coveralls.io/github/lostisland/faraday?branch=master)
6
+ [![Code Climate](https://codeclimate.com/github/lostisland/faraday/badges/gpa.svg)](https://codeclimate.com/github/lostisland/faraday)
5
7
  [![Gitter](https://badges.gitter.im/lostisland/faraday.svg)](https://gitter.im/lostisland/faraday?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
6
8
 
7
9
 
@@ -313,11 +315,6 @@ resp = test.get '/else' #=> raises "no such stub" error
313
315
  stubs.verify_stubbed_calls
314
316
  ```
315
317
 
316
- ## TODO
317
-
318
- * support streaming requests/responses
319
- * better stubbing API
320
-
321
318
  ## Supported Ruby versions
322
319
 
323
320
  This library aims to support and is [tested against][travis] the following Ruby
@@ -340,6 +337,12 @@ implementation, you will be responsible for providing patches in a timely
340
337
  fashion. If critical issues for a particular implementation exist at the time
341
338
  of a major release, support for that Ruby version may be dropped.
342
339
 
340
+ ## Contribute
341
+
342
+ Do you want to contribute to Faraday?
343
+ Open the issues page and check for the `any volunteer?` label!
344
+ But before you start coding, please read our [Contributing Guide](https://github.com/lostisland/faraday/blob/master/CONTRIBUTING.md)
345
+
343
346
  ## Copyright
344
347
 
345
348
  Copyright (c) 2009-2017 [Rick Olson](mailto:technoweenie@gmail.com), Zack Hobson.
@@ -14,7 +14,7 @@ require 'forwardable'
14
14
  # conn.get '/'
15
15
  #
16
16
  module Faraday
17
- VERSION = "0.12.2"
17
+ VERSION = "0.13.0"
18
18
 
19
19
  class << self
20
20
  # Public: Gets or sets the root path that Faraday is being loaded from.
@@ -87,10 +87,10 @@ module Faraday
87
87
 
88
88
  def net_http_connection(env)
89
89
  if proxy = env[:request][:proxy]
90
- Net::HTTP::Proxy(proxy[:uri].host, proxy[:uri].port, proxy[:user], proxy[:password])
90
+ Net::HTTP::Proxy(proxy[:uri].hostname, proxy[:uri].port, proxy[:user], proxy[:password])
91
91
  else
92
92
  Net::HTTP
93
- end.new(env[:url].host, env[:url].port || (env[:url].scheme == 'https' ? 443 : 80))
93
+ end.new(env[:url].hostname, env[:url].port || (env[:url].scheme == 'https' ? 443 : 80))
94
94
  end
95
95
 
96
96
  def configure_ssl(http, ssl)
@@ -8,6 +8,7 @@ module Faraday
8
8
  dependency 'net/http/persistent'
9
9
 
10
10
  def net_http_connection(env)
11
+ proxy_uri = nil
11
12
  if (proxy = env[:request][:proxy])
12
13
  proxy_uri = ::URI::HTTP === proxy[:uri] ? proxy[:uri].dup : ::URI.parse(proxy[:uri].to_s)
13
14
  proxy_uri.user = proxy_uri.password = nil
@@ -16,10 +17,13 @@ module Faraday
16
17
  define_method(:user) { proxy[:user] }
17
18
  define_method(:password) { proxy[:password] }
18
19
  end if proxy[:user]
19
- return Net::HTTP::Persistent.new 'Faraday', proxy_uri
20
20
  end
21
21
 
22
- Net::HTTP::Persistent.new 'Faraday'
22
+ if Net::HTTP::Persistent.instance_method(:initialize).parameters.first == [:key, :name]
23
+ Net::HTTP::Persistent.new(name: 'Faraday', proxy: proxy_uri)
24
+ else
25
+ Net::HTTP::Persistent.new('Faraday', proxy_uri)
26
+ end
23
27
  end
24
28
 
25
29
  def perform_request(http, env)
@@ -39,6 +39,9 @@ module Faraday
39
39
  # Public: Sets the default parallel manager for this connection.
40
40
  attr_writer :default_parallel_manager
41
41
 
42
+ # Public: Gets or Sets the Hash proxy options.
43
+ # attr_reader :proxy
44
+
42
45
  # Public: Initializes a new Faraday::Connection.
43
46
  #
44
47
  # url - URI or String base URL to use as a prefix for all
@@ -79,23 +82,8 @@ module Faraday
79
82
  @params.update(options.params) if options.params
80
83
  @headers.update(options.headers) if options.headers
81
84
 
82
- @proxy = nil
83
- proxy(options.fetch(:proxy) {
84
- uri = nil
85
- if URI.parse("").respond_to?(:find_proxy)
86
- case url
87
- when String
88
- uri = URI.parse(url).find_proxy
89
- when URI
90
- uri = url.find_proxy
91
- when nil
92
- uri = find_default_proxy
93
- end
94
- else
95
- uri = find_default_proxy
96
- end
97
- uri
98
- })
85
+ @proxy = options.proxy ? ProxyOptions.from(options.proxy) : proxy_from_env(url)
86
+ @temp_proxy = @proxy
99
87
 
100
88
  yield(self) if block_given?
101
89
 
@@ -292,9 +280,15 @@ module Faraday
292
280
  # Public: Gets or Sets the Hash proxy options.
293
281
  def proxy(arg = nil)
294
282
  return @proxy if arg.nil?
283
+ warn 'Warning: use of proxy(new_value) to set connection proxy have been DEPRECATED and will be removed in Faraday 1.0'
295
284
  @proxy = ProxyOptions.from(arg)
296
285
  end
297
286
 
287
+ # Public: Sets the Hash proxy options.
288
+ def proxy=(new_value)
289
+ @proxy = ProxyOptions.from(new_value)
290
+ end
291
+
298
292
  def_delegators :url_prefix, :scheme, :scheme=, :host, :host=, :port, :port=
299
293
  def_delegator :url_prefix, :path, :path_prefix
300
294
 
@@ -376,7 +370,14 @@ module Faraday
376
370
  raise ArgumentError, "unknown http method: #{method}"
377
371
  end
378
372
 
373
+ # Resets temp_proxy
374
+ @temp_proxy = self.proxy
375
+
376
+ # Set temporary proxy if request url is absolute
377
+ @temp_proxy = proxy_from_env(url) if url && URI(url).absolute?
378
+
379
379
  request = build_request(method) do |req|
380
+ req.options = req.options.merge(:proxy => @temp_proxy)
380
381
  req.url(url) if url
381
382
  req.headers.update(headers) if headers
382
383
  req.body = body if body
@@ -393,7 +394,7 @@ module Faraday
393
394
  Request.create(method) do |req|
394
395
  req.params = self.params.dup
395
396
  req.headers = self.headers.dup
396
- req.options = self.options.merge(:proxy => self.proxy)
397
+ req.options = self.options
397
398
  yield(req) if block_given?
398
399
  end
399
400
  end
@@ -443,8 +444,25 @@ module Faraday
443
444
  headers[Faraday::Request::Authorization::KEY] = header
444
445
  end
445
446
 
447
+ def proxy_from_env(url)
448
+ uri = nil
449
+ if URI.parse('').respond_to?(:find_proxy)
450
+ case url
451
+ when String
452
+ uri = URI.parse(url).find_proxy
453
+ when URI
454
+ uri = url.find_proxy
455
+ when nil
456
+ uri = find_default_proxy
457
+ end
458
+ else
459
+ warn 'no_proxy is unsupported' if ENV['no_proxy'] || ENV['NO_PROXY']
460
+ uri = find_default_proxy
461
+ end
462
+ ProxyOptions.from(uri) if uri
463
+ end
464
+
446
465
  def find_default_proxy
447
- warn 'no_proxy is unsupported' if ENV['no_proxy'] || ENV['NO_PROXY']
448
466
  uri = ENV['http_proxy']
449
467
  if uri && !uri.empty?
450
468
  uri = 'http://' + uri if uri !~ /^http/i
@@ -109,7 +109,7 @@ module Faraday
109
109
  headers = header_string.split(/\r\n/)
110
110
 
111
111
  # Find the last set of response headers.
112
- start_index = headers.rindex { |x| x.match(/^HTTP\//) }
112
+ start_index = headers.rindex { |x| x.match(/^HTTP\//) } || 0
113
113
  last_response = headers.slice(start_index, headers.size)
114
114
 
115
115
  last_response.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faraday
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.2
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rick Olson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-21 00:00:00.000000000 Z
11
+ date: 2017-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multipart-post