faraday 0.9.1 → 0.17.1

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 (74) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +196 -0
  3. data/LICENSE.md +1 -1
  4. data/README.md +192 -28
  5. data/Rakefile +6 -64
  6. data/lib/faraday/adapter/em_http.rb +17 -11
  7. data/lib/faraday/adapter/em_http_ssl_patch.rb +1 -1
  8. data/lib/faraday/adapter/em_synchrony.rb +19 -5
  9. data/lib/faraday/adapter/excon.rb +13 -11
  10. data/lib/faraday/adapter/httpclient.rb +31 -9
  11. data/lib/faraday/adapter/net_http.rb +36 -14
  12. data/lib/faraday/adapter/net_http_persistent.rb +37 -17
  13. data/lib/faraday/adapter/patron.rb +44 -21
  14. data/lib/faraday/adapter/rack.rb +1 -1
  15. data/lib/faraday/adapter/test.rb +79 -28
  16. data/lib/faraday/adapter/typhoeus.rb +4 -115
  17. data/lib/faraday/adapter.rb +10 -1
  18. data/lib/faraday/autoload.rb +1 -1
  19. data/lib/faraday/connection.rb +72 -20
  20. data/lib/faraday/deprecate.rb +101 -0
  21. data/lib/faraday/error.rb +90 -24
  22. data/lib/faraday/options.rb +43 -20
  23. data/lib/faraday/parameters.rb +56 -39
  24. data/lib/faraday/rack_builder.rb +27 -2
  25. data/lib/faraday/request/authorization.rb +1 -2
  26. data/lib/faraday/request/multipart.rb +7 -2
  27. data/lib/faraday/request/retry.rb +84 -19
  28. data/lib/faraday/request.rb +22 -0
  29. data/lib/faraday/response/logger.rb +29 -8
  30. data/lib/faraday/response/raise_error.rb +7 -3
  31. data/lib/faraday/response.rb +9 -5
  32. data/lib/faraday/utils.rb +32 -3
  33. data/lib/faraday.rb +14 -34
  34. data/spec/faraday/deprecate_spec.rb +69 -0
  35. data/spec/faraday/error_spec.rb +102 -0
  36. data/spec/faraday/response/raise_error_spec.rb +95 -0
  37. data/spec/spec_helper.rb +104 -0
  38. data/test/adapters/em_http_test.rb +10 -0
  39. data/test/adapters/em_synchrony_test.rb +22 -10
  40. data/test/adapters/excon_test.rb +10 -0
  41. data/test/adapters/httpclient_test.rb +14 -1
  42. data/test/adapters/integration.rb +17 -8
  43. data/test/adapters/logger_test.rb +65 -11
  44. data/test/adapters/net_http_persistent_test.rb +96 -2
  45. data/test/adapters/net_http_test.rb +67 -2
  46. data/test/adapters/patron_test.rb +28 -8
  47. data/test/adapters/rack_test.rb +8 -1
  48. data/test/adapters/test_middleware_test.rb +46 -3
  49. data/test/adapters/typhoeus_test.rb +19 -9
  50. data/test/composite_read_io_test.rb +16 -18
  51. data/test/connection_test.rb +294 -78
  52. data/test/env_test.rb +55 -5
  53. data/test/helper.rb +11 -17
  54. data/test/middleware/retry_test.rb +115 -10
  55. data/test/middleware_stack_test.rb +97 -10
  56. data/test/options_test.rb +97 -16
  57. data/test/parameters_test.rb +94 -1
  58. data/test/request_middleware_test.rb +24 -40
  59. data/test/response_middleware_test.rb +4 -4
  60. data/test/utils_test.rb +40 -0
  61. metadata +21 -66
  62. data/.document +0 -6
  63. data/CONTRIBUTING.md +0 -36
  64. data/Gemfile +0 -25
  65. data/faraday.gemspec +0 -34
  66. data/script/cached-bundle +0 -46
  67. data/script/console +0 -7
  68. data/script/generate_certs +0 -42
  69. data/script/package +0 -7
  70. data/script/proxy-server +0 -42
  71. data/script/release +0 -17
  72. data/script/s3-put +0 -71
  73. data/script/server +0 -36
  74. data/script/test +0 -172
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 1c31dbb021fc6a43b4f0b102a9a3ccf52a72303a
4
- data.tar.gz: 54da868027777adb5a21145bd6433b0154af2297
2
+ SHA256:
3
+ metadata.gz: 16a3bb1447dde55604486c5a3a912281318ca8d0a211008623bcafb270a104ea
4
+ data.tar.gz: 966aaefe77900eab1bd1687bf7ce57950e0dbc8fb8dcd7a062fddf6be4393c4f
5
5
  SHA512:
6
- metadata.gz: 22c1c286687ca596bd1d6b7d9a6a3749731f6d8962a5bbbe7e1e39cf22e364b92010ae44446cf1804ba10567a2e6409cc2be537375d9f47ace9bca909196dcd3
7
- data.tar.gz: 7e8116cdeea918b8e7de661ec6d49d839960e26f136903e53db62e8cc353f89b3ac053d5efe6401995129418ae4dfce8fda9c8a471093223dca08002615d10e1
6
+ metadata.gz: b016c9c3ea03bba4a9a40325f0494ef8a096e6c67d46ced7cb13da8e2bfeafca92107bc971f276ea883249219e13fa3f5f67e6c73d43c6ce66c6827108457e86
7
+ data.tar.gz: 23e0a83830645895da998a9961d43747de7da1ee9428ea15a68776e1edb346f67c1b66d9403f3e4e0b5c40790e6adbf9bfa8dbb26db0cf79d4fafcb292c9e7ff
data/CHANGELOG.md CHANGED
@@ -1,5 +1,201 @@
1
1
  # Faraday Changelog
2
2
 
3
+ ## v0.17.1
4
+
5
+ Final release before Faraday v1.0, with important fixes for Ruby 2.7.
6
+
7
+ Fixes:
8
+
9
+ * RaiseError response middleware raises exception if HTTP client returns a nil
10
+ status. (#1042)
11
+
12
+ Misc:
13
+
14
+ * Fix Ruby 2.7 warnings (#1009)
15
+ * Add `Faraday::Deprecate` to warn about upcoming v1.0 changes. (#1054, #1059,
16
+ #1076, #1077)
17
+ * Add release notes up to current in CHANGELOG.md (#1066)
18
+ * Port minimal rspec suite from main branch to run backported tests. (#1058)
19
+
20
+ ## v0.17.0
21
+
22
+ This release is the same as v0.15.4. It was pushed to cover up releases
23
+ v0.16.0-v0.16.2.
24
+
25
+ ## v0.15.4
26
+
27
+ * Expose `pool_size` as a option for the NetHttpPersistent adapter (#834)
28
+
29
+ ## v0.15.3
30
+
31
+ * Make Faraday::Request serialisable with Marshal. (#803)
32
+ * Add DEFAULT_EXCEPTIONS constant to Request::Retry (#814)
33
+ * Add support for Ruby 2.6 Net::HTTP write_timeout (#824)
34
+
35
+ ## v0.15.2
36
+
37
+ * Prevents `Net::HTTP` adapters to retry request internally by setting `max_retries` to 0 if available (Ruby 2.5+). (#799)
38
+ * Fixes `NestedParamsEncoder` handling of empty array values (#801)
39
+
40
+ ## v0.15.1
41
+
42
+ * NetHttpPersistent adapter better reuse of SSL connections (#793)
43
+ * Refactor: inline cached_connection (#797)
44
+ * Logger middleware: use $stdout instead of STDOUT (#794)
45
+ * Fix: do not memoize/reuse Patron session (#796)
46
+
47
+ Also in this release:
48
+
49
+ * Allow setting min/max ssl version for Net::HTTP (#792)
50
+ * Allow setting min/max ssl version for Excon (#795)
51
+
52
+ ## v0.15.0
53
+
54
+ Features:
55
+
56
+ * Added retry block option to retry middleware. (#770)
57
+ * Retry middleware improvements (honour Retry-After header, retry statuses) (#773)
58
+ * Improve response logger middleware output (#784)
59
+
60
+ Fixes:
61
+
62
+ * Remove unused class error (#767)
63
+ * Fix minor typo in README (#760)
64
+ * Reuse persistent connections when using net-http-persistent (#778)
65
+ * Fix Retry middleware documentation (#781)
66
+ * Returns the http response when giving up on retrying by status (#783)
67
+
68
+ ## v0.14.0
69
+
70
+ Features:
71
+
72
+ * Allow overriding env proxy (#754)
73
+ * Remove legacy Typhoeus adapter (#715)
74
+ * External Typhoeus Adapter Compatibility (#748)
75
+ * Warn about missing adapter when making a request (#743)
76
+ * Faraday::Adapter::Test stubs now support entire urls (with host) (#741)
77
+
78
+ Fixes:
79
+
80
+ * If proxy is manually provided, this takes priority over `find_proxy` (#724)
81
+ * Fixes the behaviour for Excon's open_timeout (not setting write_timeout anymore) (#731)
82
+ * Handle all connection timeout messages in Patron (#687)
83
+
84
+ ## v0.13.1
85
+
86
+ * Fixes an incompatibility with Addressable::URI being used as uri_parser
87
+
88
+ ## v0.13.0
89
+
90
+ Features:
91
+
92
+ * Dynamically reloads the proxy when performing a request on an absolute domain (#701)
93
+ * Adapter support for Net::HTTP::Persistent v3.0.0 (#619)
94
+
95
+ Fixes:
96
+
97
+ * Prefer #hostname over #host. (#714)
98
+ * Fixes an edge-case issue with response headers parsing (missing HTTP header) (#719)
99
+
100
+ ## v0.12.2
101
+
102
+ * Parse headers from aggregated proxy requests/responses (#681)
103
+ * Guard against invalid middleware configuration with warning (#685)
104
+ * Do not use :insecure option by default in Patron (#691)
105
+ * Fixes an issue with HTTPClient not raising a `Faraday::ConnectionFailed` (#702)
106
+ * Fixes YAML serialization/deserialization for `Faraday::Utils::Headers` (#690)
107
+ * Fixes an issue with Options having a nil value (#694)
108
+ * Fixes an issue with Faraday.default_connection not using Faraday.default_connection_options (#698)
109
+ * Fixes an issue with Options.merge! and Faraday instrumentation middleware (#710)
110
+
111
+ ## v0.12.1
112
+
113
+ * Fix an issue with Patron tests failing on jruby
114
+ * Fix an issue with new `rewind_files` feature that was causing an exception when the body was not an Hash
115
+ * Expose wrapped_exception in all client errors
116
+ * Add Authentication Section to the ReadMe
117
+
118
+ ## v0.12.0.1
119
+
120
+ * Hotfix release to address an issue with TravisCI deploy on Rubygems
121
+
122
+ ## v0.12.0
123
+
124
+ Features:
125
+
126
+ * Proxy feature now relies on Ruby `URI::Generic#find_proxy` and can use `no_proxy` ENV variable (not compatible with ruby < 2.0)
127
+ * Adds support for `context` request option to pass arbitrary information to middlewares
128
+
129
+ Fixes:
130
+
131
+ * Fix an issue with options that was causing new options to override defaults ones unexpectedly
132
+ * Rewind `UploadIO`s on retry to fix a compatibility issue
133
+ * Make multipart boundary unique
134
+ * Improvements in `README.md`
135
+
136
+ ## v0.11.0
137
+
138
+ Features:
139
+
140
+ * Add `filter` method to Logger middleware
141
+ * Add support for Ruby2.4 and Minitest 6
142
+ * Introduce block syntax to customise the adapter
143
+
144
+ Fixes:
145
+
146
+ * Fix an issue that was allowing to override `default_connection_options` from a connection instance
147
+ * Fix a bug that was causing newline escape characters ("\n") to be used when building the Authorization header
148
+
149
+ ## v0.10.1
150
+
151
+ - Fix an issue with HTTPClient adapter that was causing the SSL to be reset on every request
152
+ - Rescue `IOError` instead of specific subclass
153
+ - `Faraday::Utils::Headers` can now be successfully serialised in YAML
154
+ - Handle `default_connection_options` set with hash
155
+
156
+ ## v0.10.0
157
+
158
+ Breaking changes:
159
+ - Drop support for Ruby 1.8
160
+
161
+ Features:
162
+ - Include wrapped exception/reponse in ClientErrors
163
+ - Add `response.reason_phrase`
164
+ - Provide option to selectively skip logging request/response headers
165
+ - Add regex support for pattern matching in `test` adapter
166
+
167
+ Fixes:
168
+ - Add `Faraday.respond_to?` to find methods managed by `method_missing`
169
+ - em-http: `request.host` instead of `connection.host` should be taken for SSL validations
170
+ - Allow `default_connection_options` to be merged when options are passed as url parameter
171
+ - Improve splitting key-value pairs in raw HTTP headers
172
+
173
+ ## v0.9.2
174
+
175
+ Adapters:
176
+ - Enable gzip compression for httpclient
177
+ - Fixes default certificate store for httpclient not having default paths.
178
+ - Make excon adapter compatible with 0.44 excon version
179
+ - Add compatibility with Patron 0.4.20
180
+ - Determine default port numbers in Net::HTTP adapters (Addressable compatibility)
181
+ - em-http: wrap "connection closed by server" as ConnectionFailed type
182
+ - Wrap Errno::ETIMEDOUT in Faraday::Error::TimeoutError
183
+
184
+ Utils:
185
+ - Add Rack-compatible support for parsing `a[][b]=c` nested queries
186
+ - Encode nil values in queries different than empty strings. Before: `a=`; now: `a`.
187
+ - Have `Faraday::Utils::Headers#replace` clear internal key cache
188
+ - Dup the internal key cache when a Headers hash is copied
189
+
190
+ Env and middleware:
191
+ - Ensure `env` stored on middleware response has reference to the response
192
+ - Ensure that Response properties are initialized during `on_complete` (VCR compatibility)
193
+ - Copy request options in Faraday::Connection#dup
194
+ - Env custom members should be copied by Env.from(env)
195
+ - Honour per-request `request.options.params_encoder`
196
+ - Fix `interval_randomness` data type for Retry middleware
197
+ - Add maximum interval option for Retry middleware
198
+
3
199
  ## v0.9.1
4
200
 
5
201
  * Refactor Net:HTTP adapter so that with_net_http_connection can be overridden to allow pooled connections. (@Ben-M)
data/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009-2013 Rick Olson, Zack Hobson
1
+ Copyright (c) 2009-2017 Rick Olson, Zack Hobson
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,30 +1,77 @@
1
1
  # Faraday
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/faraday.svg)](https://rubygems.org/gems/faraday)
4
+ [![Build Status](https://travis-ci.org/lostisland/faraday.svg?branch=master)](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)
7
+ [![Gitter](https://badges.gitter.im/lostisland/faraday.svg)](https://gitter.im/lostisland/faraday?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
8
+
9
+
3
10
  Faraday is an HTTP client lib that provides a common interface over many
4
11
  adapters (such as Net::HTTP) and embraces the concept of Rack middleware when
5
12
  processing the request/response cycle.
6
13
 
7
- Faraday supports these adapters:
14
+ Faraday supports these adapters out of the box:
8
15
 
9
- * Net::HTTP
16
+ * [Net::HTTP][net_http] _(default)_
17
+ * [Net::HTTP::Persistent][persistent]
10
18
  * [Excon][]
11
- * [Typhoeus][]
12
19
  * [Patron][]
13
20
  * [EventMachine][]
14
21
  * [HTTPClient][]
15
22
 
23
+ Adapters are slowly being moved into their own gems, or bundled with HTTP clients:
24
+
25
+ * [Typhoeus][]
26
+
16
27
  It also includes a Rack adapter for hitting loaded Rack applications through
17
28
  Rack::Test, and a Test adapter for stubbing requests by hand.
18
29
 
30
+ ## API documentation
31
+
32
+ Available at [rubydoc.info](http://www.rubydoc.info/gems/faraday).
33
+
19
34
  ## Usage
20
35
 
36
+ ### Basic Use
37
+
38
+ ```ruby
39
+ response = Faraday.get 'http://sushi.com/nigiri/sake.json'
40
+ ```
41
+ A simple `get` request can be performed by using the syntax described above. This works if you don't need to set up anything; you can roll with just the default middleware
42
+ stack and default adapter (see [Faraday::RackBuilder#initialize](https://github.com/lostisland/faraday/blob/master/lib/faraday/rack_builder.rb)).
43
+
44
+ A more flexible way to use Faraday is to start with a Connection object. If you want to keep the same defaults, you can use this syntax:
45
+
46
+ ```ruby
47
+ conn = Faraday.new(:url => 'http://www.example.com')
48
+ response = conn.get '/users' # GET http://www.example.com/users'
49
+ ```
50
+
51
+ Connections can also take an options hash as a parameter or be configured by using a block. Checkout the section called [Advanced middleware usage](#advanced-middleware-usage) for more details about how to use this block for configurations.
52
+ Since the default middleware stack uses url\_encoded middleware and default adapter, use them on building your own middleware stack.
53
+
21
54
  ```ruby
22
55
  conn = Faraday.new(:url => 'http://sushi.com') do |faraday|
23
56
  faraday.request :url_encoded # form-encode POST params
24
- faraday.response :logger # log requests to STDOUT
57
+ faraday.response :logger # log requests to $stdout
58
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
59
+ end
60
+
61
+ # Filter sensitive information from logs with a regex matcher
62
+
63
+ conn = Faraday.new(:url => 'http://sushi.com/api_key=s3cr3t') do |faraday|
64
+ faraday.request :url_encoded # form-encode POST params
65
+ faraday.response :logger do | logger |
66
+ logger.filter(/(api_key=)(\w+)/,'\1[REMOVED]')
67
+ end
25
68
  faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
26
69
  end
70
+ ```
71
+
72
+ Once you have the connection object, use it to make HTTP requests. You can pass parameters to it in a few different ways:
27
73
 
74
+ ```ruby
28
75
  ## GET ##
29
76
 
30
77
  response = conn.get '/nigiri/sake.json' # GET http://sushi.com/nigiri/sake.json
@@ -40,7 +87,11 @@ end
40
87
  ## POST ##
41
88
 
42
89
  conn.post '/nigiri', { :name => 'Maguro' } # POST "name=maguro" to http://sushi.com/nigiri
90
+ ```
91
+
92
+ Some configuration options can be adjusted per request:
43
93
 
94
+ ```ruby
44
95
  # post payload as JSON instead of "www-form-urlencoded" encoding:
45
96
  conn.post do |req|
46
97
  req.url '/nigiri'
@@ -57,11 +108,74 @@ conn.get do |req|
57
108
  end
58
109
  ```
59
110
 
60
- If you don't need to set up anything, you can roll with just the default middleware
61
- stack and default adapter (see [Faraday::RackBuilder#initialize](https://github.com/lostisland/faraday/blob/master/lib/faraday/rack_builder.rb)):
111
+ And you can inject arbitrary data into the request using the `context` option:
62
112
 
63
113
  ```ruby
64
- response = Faraday.get 'http://sushi.com/nigiri/sake.json'
114
+ # Anything you inject using context option will be available in the env on all middlewares
115
+
116
+ conn.get do |req|
117
+ req.url '/search'
118
+ req.options.context = {
119
+ foo: 'foo',
120
+ bar: 'bar'
121
+ }
122
+ end
123
+ ```
124
+
125
+ ### Changing how parameters are serialized
126
+
127
+ Sometimes you need to send the same URL parameter multiple times with different
128
+ values. This requires manually setting the parameter encoder and can be done on
129
+ either per-connection or per-request basis.
130
+
131
+ ```ruby
132
+ # per-connection setting
133
+ conn = Faraday.new :request => { :params_encoder => Faraday::FlatParamsEncoder }
134
+
135
+ conn.get do |req|
136
+ # per-request setting:
137
+ # req.options.params_encoder = my_encoder
138
+ req.params['roll'] = ['california', 'philadelphia']
139
+ end
140
+ # GET 'http://sushi.com?roll=california&roll=philadelphia'
141
+ ```
142
+
143
+ The value of Faraday `params_encoder` can be any object that responds to:
144
+
145
+ * `encode(hash) #=> String`
146
+ * `decode(string) #=> Hash`
147
+
148
+ The encoder will affect both how query strings are processed and how POST bodies
149
+ get serialized. The default encoder is Faraday::NestedParamsEncoder.
150
+
151
+ ## Authentication
152
+
153
+ Basic and Token authentication are handled by Faraday::Request::BasicAuthentication and Faraday::Request::TokenAuthentication respectively. These can be added as middleware manually or through the helper methods.
154
+
155
+ ```ruby
156
+ Faraday.new(...) do |conn|
157
+ conn.basic_auth('username', 'password')
158
+ end
159
+
160
+ Faraday.new(...) do |conn|
161
+ conn.token_auth('authentication-token')
162
+ end
163
+ ```
164
+
165
+ ## Proxy
166
+
167
+ Faraday will try to automatically infer the proxy settings from your system using `URI#find_proxy`.
168
+ This will retrieve them from environment variables such as http_proxy, ftp_proxy, no_proxy, etc.
169
+ If for any reason you want to disable this behaviour, you can do so by setting the global varibale `ignore_env_proxy`:
170
+
171
+ ```ruby
172
+ Faraday.ignore_env_proxy = true
173
+ ```
174
+
175
+ You can also specify a custom proxy when initializing the connection
176
+
177
+ ```ruby
178
+ Faraday.new('http://www.example.com', :proxy => 'http://proxy.com')
65
179
  ```
66
180
 
67
181
  ## Advanced middleware usage
@@ -75,7 +189,11 @@ Faraday.new(...) do |conn|
75
189
  # POST/PUT params encoders:
76
190
  conn.request :multipart
77
191
  conn.request :url_encoded
192
+
193
+ # add custom middleware
194
+ conn.use MyMiddleware
78
195
 
196
+ # Last middleware must be the adapter:
79
197
  conn.adapter :net_http
80
198
  end
81
199
  ```
@@ -138,6 +256,53 @@ later, response. Some keys are:
138
256
  :response_headers
139
257
  ```
140
258
 
259
+ ## Ad-hoc adapters customization
260
+
261
+ Faraday is intended to be a generic interface between your code and the adapter. However, sometimes you need to access a feature specific to one of the adapters that is not covered in Faraday's interface.
262
+
263
+ When that happens, you can pass a block when specifying the adapter to customize it. The block parameter will change based on the adapter you're using. See below for some examples.
264
+
265
+ ### NetHttp
266
+ ```ruby
267
+ conn = Faraday.new(...) do |f|
268
+ f.adapter :net_http do |http| # yields Net::HTTP
269
+ http.idle_timeout = 100
270
+ http.verify_callback = lambda do | preverify_ok, cert_store |
271
+ # do something here...
272
+ end
273
+ end
274
+ end
275
+ ```
276
+
277
+ ### NetHttpPersistent
278
+ ```ruby
279
+ conn = Faraday.new(...) do |f|
280
+ f.adapter :net_http_persistent, pool_size: 5 do |http| # yields Net::HTTP::Persistent
281
+ http.idle_timeout = 100
282
+ http.retry_change_requests = true
283
+ end
284
+ end
285
+ ```
286
+
287
+ ### Patron
288
+ ```ruby
289
+ conn = Faraday.new(...) do |f|
290
+ f.adapter :patron do |session| # yields Patron::Session
291
+ session.max_redirects = 10
292
+ end
293
+ end
294
+ ```
295
+
296
+ ### HTTPClient
297
+ ```ruby
298
+ conn = Faraday.new(...) do |f|
299
+ f.adapter :httpclient do |client| # yields HTTPClient
300
+ client.keep_alive_timeout = 20
301
+ client.ssl_config.timeout = 25
302
+ end
303
+ end
304
+ ```
305
+
141
306
  ## Using Faraday for testing
142
307
 
143
308
  ```ruby
@@ -173,23 +338,14 @@ resp = test.get '/else' #=> raises "no such stub" error
173
338
  stubs.verify_stubbed_calls
174
339
  ```
175
340
 
176
- ## TODO
177
-
178
- * support streaming requests/responses
179
- * better stubbing API
180
-
181
341
  ## Supported Ruby versions
182
342
 
183
343
  This library aims to support and is [tested against][travis] the following Ruby
184
344
  implementations:
185
345
 
186
- * MRI 1.8.7
187
- * MRI 1.9.2
188
- * MRI 1.9.3
189
- * MRI 2.0.0
190
- * MRI 2.1.0
191
- * [JRuby][]
192
- * [Rubinius][]
346
+ * Ruby 1.9.3+
347
+ * [JRuby][] 1.7+
348
+ * [Rubinius][] 2+
193
349
 
194
350
  If something doesn't work on one of these Ruby versions, it's a bug.
195
351
 
@@ -204,17 +360,25 @@ implementation, you will be responsible for providing patches in a timely
204
360
  fashion. If critical issues for a particular implementation exist at the time
205
361
  of a major release, support for that Ruby version may be dropped.
206
362
 
363
+ ## Contribute
364
+
365
+ Do you want to contribute to Faraday?
366
+ Open the issues page and check for the `help wanted` label!
367
+ But before you start coding, please read our [Contributing Guide](https://github.com/lostisland/faraday/blob/master/.github/CONTRIBUTING.md)
368
+
207
369
  ## Copyright
208
370
 
209
- Copyright (c) 2009-2013 [Rick Olson](mailto:technoweenie@gmail.com), Zack Hobson.
371
+ Copyright (c) 2009-2017 [Rick Olson](mailto:technoweenie@gmail.com), Zack Hobson.
210
372
  See [LICENSE][] for details.
211
373
 
212
- [travis]: http://travis-ci.org/lostisland/faraday
213
- [excon]: https://github.com/geemus/excon#readme
214
- [typhoeus]: https://github.com/typhoeus/typhoeus#readme
215
- [patron]: http://toland.github.com/patron/
374
+ [net_http]: http://ruby-doc.org/stdlib/libdoc/net/http/rdoc/Net/HTTP.html
375
+ [persistent]: https://github.com/drbrain/net-http-persistent
376
+ [travis]: https://travis-ci.org/lostisland/faraday
377
+ [excon]: https://github.com/excon/excon#readme
378
+ [patron]: http://toland.github.io/patron/
216
379
  [eventmachine]: https://github.com/igrigorik/em-http-request#readme
217
- [httpclient]: https://github.com/nahi/httpclient
218
- [jruby]: http://jruby.org/
219
- [rubinius]: http://rubini.us/
220
- [license]: LICENSE.md
380
+ [httpclient]: https://github.com/nahi/httpclient
381
+ [typhoeus]: https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/adapters/faraday.rb
382
+ [jruby]: http://jruby.org/
383
+ [rubinius]: http://rubini.us/
384
+ [license]: LICENSE.md
data/Rakefile CHANGED
@@ -1,71 +1,13 @@
1
- require 'date'
2
- require 'fileutils'
3
- require 'openssl'
4
- require 'rake/testtask'
5
- require 'bundler'
6
- Bundler::GemHelper.install_tasks
7
-
8
- task :default => :test
9
-
10
- ## helper functions
11
-
12
- def name
13
- @name ||= Dir['*.gemspec'].first.split('.').first
14
- end
1
+ # frozen_string_literal: true
15
2
 
16
- def version
17
- line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
18
- line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
19
- end
20
-
21
- def gemspec_file
22
- "#{name}.gemspec"
23
- end
24
-
25
- def gem_file
26
- "#{name}-#{version}.gem"
27
- end
3
+ require 'rake/testtask'
4
+ require 'rspec/core/rake_task'
28
5
 
29
- def replace_header(head, header_name)
30
- head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
31
- end
6
+ RSpec::Core::RakeTask.new(:spec)
32
7
 
33
- # Adapted from WEBrick::Utils. Skips cert extensions so it
34
- # can be used as a CA bundle
35
- def create_self_signed_cert(bits, cn, comment)
36
- rsa = OpenSSL::PKey::RSA.new(bits)
37
- cert = OpenSSL::X509::Certificate.new
38
- cert.version = 2
39
- cert.serial = 1
40
- name = OpenSSL::X509::Name.new(cn)
41
- cert.subject = name
42
- cert.issuer = name
43
- cert.not_before = Time.now
44
- cert.not_after = Time.now + (365*24*60*60)
45
- cert.public_key = rsa.public_key
46
- cert.sign(rsa, OpenSSL::Digest::SHA1.new)
47
- return [cert, rsa]
48
- end
49
-
50
- ## standard tasks
8
+ task :default => :test
51
9
 
52
10
  desc "Run all tests"
53
- task :test do
11
+ task :test => :spec do
54
12
  exec 'script/test'
55
13
  end
56
-
57
- desc "Generate certificates for SSL tests"
58
- task :'test:generate_certs' do
59
- cert, key = create_self_signed_cert(1024, [['CN', 'localhost']], 'Faraday Test CA')
60
- FileUtils.mkdir_p 'tmp'
61
- File.open('tmp/faraday-cert.key', 'w') {|f| f.puts(key) }
62
- File.open('tmp/faraday-cert.crt', 'w') {|f| f.puts(cert.to_s) }
63
- end
64
-
65
- file 'tmp/faraday-cert.key' => :'test:generate_certs'
66
- file 'tmp/faraday-cert.crt' => :'test:generate_certs'
67
-
68
- desc "Open an irb session preloaded with this library"
69
- task :console do
70
- sh "irb -rubygems -r ./lib/#{name}.rb"
71
- end
@@ -124,9 +124,9 @@ module Faraday
124
124
  end
125
125
  rescue EventMachine::Connectify::CONNECTError => err
126
126
  if err.message.include?("Proxy Authentication Required")
127
- raise Error::ConnectionFailed, %{407 "Proxy Authentication Required "}
127
+ raise Faraday::ConnectionFailed, %{407 "Proxy Authentication Required "}
128
128
  else
129
- raise Error::ConnectionFailed, err
129
+ raise Faraday::ConnectionFailed, err
130
130
  end
131
131
  rescue => err
132
132
  if defined?(OpenSSL) && OpenSSL::SSL::SSLError === err
@@ -138,9 +138,11 @@ module Faraday
138
138
 
139
139
  # TODO: reuse the connection to support pipelining
140
140
  def perform_single_request(env)
141
- req = EventMachine::HttpRequest.new(env[:url], connection_config(env))
141
+ req = create_request(env)
142
142
  req.setup_request(env[:method], request_config(env)).callback { |client|
143
- save_response(env, client.response_header.status, client.response) do |resp_headers|
143
+ status = client.response_header.status
144
+ reason = client.response_header.http_reason
145
+ save_response(env, status, client.response, nil, reason) do |resp_headers|
144
146
  client.response_header.each do |name, value|
145
147
  resp_headers[name.to_sym] = value
146
148
  end
@@ -148,20 +150,24 @@ module Faraday
148
150
  }
149
151
  end
150
152
 
153
+ def create_request(env)
154
+ EventMachine::HttpRequest.new(env[:url], connection_config(env).merge(@connection_options))
155
+ end
156
+
151
157
  def error_message(client)
152
158
  client.error or "request failed"
153
159
  end
154
160
 
155
161
  def raise_error(msg)
156
- errklass = Faraday::Error::ClientError
162
+ errklass = Faraday::ClientError
157
163
  if msg == Errno::ETIMEDOUT
158
- errklass = Faraday::Error::TimeoutError
164
+ errklass = Faraday::TimeoutError
159
165
  msg = "request timed out"
160
166
  elsif msg == Errno::ECONNREFUSED
161
- errklass = Faraday::Error::ConnectionFailed
167
+ errklass = Faraday::ConnectionFailed
162
168
  msg = "connection refused"
163
169
  elsif msg == "connection closed by server"
164
- errklass = Faraday::Error::ConnectionFailed
170
+ errklass = Faraday::ConnectionFailed
165
171
  end
166
172
  raise errklass, msg
167
173
  end
@@ -187,11 +193,11 @@ module Faraday
187
193
 
188
194
  def running?() @running end
189
195
 
190
- def add
196
+ def add(&block)
191
197
  if running?
192
198
  perform_request { yield }
193
199
  else
194
- @registered_procs << Proc.new
200
+ @registered_procs << block
195
201
  end
196
202
  @num_registered += 1
197
203
  end
@@ -205,7 +211,7 @@ module Faraday
205
211
  end
206
212
  end
207
213
  if @errors.size > 0
208
- raise Faraday::Error::ClientError, @errors.first || "connection failed"
214
+ raise Faraday::ClientError, @errors.first || "connection failed"
209
215
  end
210
216
  end
211
217
  ensure
@@ -39,7 +39,7 @@ module EmHttpSslPatch
39
39
  end
40
40
 
41
41
  def host
42
- parent.connopts.host
42
+ parent.uri.host
43
43
  end
44
44
 
45
45
  def certificate_store