930 Commits

Author SHA1 Message Date
Mislav Marohnić
fba7ce503d Merge pull request #532 from lostisland/vcr-compat
VCR compatibility fix: untangle the response env mess
2015-10-06 17:28:20 +02:00
Ricardo Valeriano
f73d13ee09 Wrap Errno::ETIMEDOUT in Faraday::Error::TimeoutError
Closes #324
2015-10-06 16:32:03 +02:00
Mislav Marohnić
c94890c499 Merge pull request #405 from dtaniwaki/patch-1
Fix interval_randomness data type
2015-10-06 16:19:30 +02:00
Mislav Marohnić
f737e4199c Merge pull request #531 from lostisland/nested-arrays-parsing
Add proper support for parsing `a[][b]=c` nested queries
2015-10-06 16:08:10 +02:00
Mislav Marohnić
a410d77110 Ensure that Response properties are initialized during on_complete
This fixes VCR compatibility in parallel test mode.
2015-10-06 15:51:53 +02:00
Mislav Marohnić
eac07e5d87 Merge branch 'master' into vcr-compat 2015-10-03 18:09:39 +02:00
Mislav Marohnić
b1964f7758 Merge pull request #409 from loopj/remove-autoload-remnant
Remove remnant `require_libs` call from `Faraday::Utils`
2015-10-03 05:42:06 +02:00
Mislav Marohnić
1f29d62e21 Merge pull request #468 from chipiga/master
Make excon adapter compatible with 0.44 excon version
2015-10-03 05:35:29 +02:00
Mislav Marohnić
ac73c46a78 Merge pull request #478 from jrafanie/dup_names_hash_when_copying_header_hash
Dup the @names hash when the Headers hash is copied.
2015-10-03 01:56:07 +02:00
Mislav Marohnić
b3e49cba6c Merge pull request #376 from ketan/header-hash-repace
Faraday::Utils::Headers#replace has side-effects
2015-10-03 01:55:32 +02:00
Mislav Marohnić
9e035a65b3 Further simplify nested params parsing and add more tests 2015-10-03 01:23:33 +02:00
Mislav Marohnić
f78d51da17 Encode nil values in queries different than empty strings
Now:

```rb
encode(:a => nil, :b => "") #=> "a&b="
```
2015-10-03 01:23:33 +02:00
Mislav Marohnić
6ffc244823 Add note about still not being fully compatible with Rack 2015-10-03 01:23:32 +02:00
Mislav Marohnić
1ffc29eb54 Add proper support for parsing a[][b]=c nested queries
This matches behavior of Rack::Utils.parse_nested_query which Rails adopts.
2015-10-03 01:23:32 +02:00
Mislav Marohnić
d98b6408e3 Merge pull request #493 from renderedtext/maximum-retry-interval
Maximum interval option for Retry middleware
2015-10-02 18:06:21 +02:00
Mislav Marohnić
dedd377c8a Merge branch 'master' into params-encoder 2015-10-02 17:06:30 +02:00
Mislav Marohnić
86e5fa4ee3 em-http: wrap "connection closed by server" as ConnectionFailed type
This is bizarrely returned by em-http when failing to authenticate with
the proxy server, but only on Travis and not on my Mac.

https://travis-ci.org/lostisland/faraday/jobs/83207905
2015-10-02 01:03:46 +02:00
Mislav Marohnić
7578f0828d Merge branch 'env-custom-members' 2015-10-02 00:07:43 +02:00
Mislav Marohnić
441d8ac979 Simplify copying custom_members to new Env instance 2015-10-02 00:06:53 +02:00
David Cornu
ad226f75ab Honour request.options.params_encoder 2015-09-26 12:13:09 -04:00
risk danger olson
5bfa4bf948 Merge pull request #511 from jhass/fix_connection_dup
Fix Faraday::Connection#dup
2015-09-23 05:47:05 -07:00
nicholas a. evans
03f373a1fb Env custom members should be copied by Env.from(env)
Fixes lostisland/faraday#408.

If middleware or adapters add custom members to env, those members should be
retained.
2015-09-21 16:58:59 -04:00
Mislav Marohnić
faf501b277 Fix default port numbers for Net::HTTP adapters
When Addressable::URI is used, the `port` property will be nil unless
port was explicitly specified. This made Addressable unusable in HTTPS
scenarios with Net::HTTP adapters, which would default to port 80 even
when the scheme was "https".
2015-08-20 22:25:47 -07:00
Jonne Haß
7b4e048a58 Copy request options in Faraday::Connection#dup
Otherwise they are lost and reset to the defaults, especially
for the timeout options that is rather unexpected.
2015-08-14 13:04:22 +02:00
Peter Vandenberk
2c97f3ca58 Net::HTTP::Persistent adapter not experimental 2015-07-21 11:02:01 -07:00
John Bellone
5d40163dd9 [httpclient] Fixes default certificate store not having default paths.
This came up while debugging an issue with the latest Berkshelf
release. It seems that the net_http.rb adapter did this in the exact
same way (calls #set_default_paths on the X509::Store) but for some
reason it was neglected when httpclient.rb adapter was written.

It is expectation that, by default, the system certificate store is utilized.
2015-07-06 15:19:31 -04:00
Igor Šarčević
b43e0682f5 Maximum interval option for Retry middleware 2015-07-01 11:00:57 +00:00
Ben Hanzl
e36f029d39 Add compatibility with Patron 0.4.20
Version 0.4.20 of the Patron gem uses strings instead of symbols for
validating valid request actions.
2015-06-12 01:58:58 +02:00
Joe Rafaniello
4615ec4eaf Dup the @names hash when the Headers hash is copied.
Without this change, a connection's header and each request's header
all reference the same `@names` hash object so any request that modified
it via delete or other mutating methods, would affect the headers of other
requests and the connection.

In [travis.rb](9b3eb05542/lib/travis/client/session.rb (L206-209)), it was doing:

```ruby
  connection.public_send(verb, url, *args) do |request|
    next if request.path !~ /^https?:/ or request.path.start_with? api_endpoint
    request.headers.delete("Authorization")
  end
```

This caused the headers of multiple requests (and the connection) to share
the same `@names` hash object, resulting in `@names` and the Header hash
to go out of sync:

thing| @names | Header
--- | --- | --- | ---
connection | no Authorization | Has Authorization
request 1 | no Authorization | no Authorization
request 2 | no Authorization | Has Authorization

Because Headers uses the `@names` to determine if it `includes?` a key or
if there's a key to `delete`, you would have Authorization in the headers
but it wouldn't be removed because `@names` didn't have it.
2015-05-15 17:16:32 -04:00
Josh Cheek
fc4cec558e Env stored on middleware response has reference to the response
Synopsis
--------

The `Env` that gets stored on the `Response` does not contain
a reference to that response. This env is a copy of the env that
was passed through the middleware stack. Thus if the env
passed to `app.call` is used, it has the response, but if the one
from the `Response` is used, then it does not. This happens when,
for example, you invoke the `on_complete` hook on the response,
after it has finished.

Fixes Longstanding VCR issue
----------------------------

Fixes https://github.com/vcr/vcr/issues/386

A longstanding issue in VCR's integration with v0.9.x
It was worked around in this commit: https://github.com/vcr/vcr/pull/439
And is merged into master, but is not released.
Merging this will fix the issue, without the changes to VCR needing to
be released.

The old code, which is currently released, and gets its env from the
Request can be seen
[here](cb9696c44d%5E/lib/vcr/middleware/faraday.rb#L99-105)

Fixes Faraday Issue
-------------------

Fixes https://github.com/lostisland/faraday/issues/441
which identifies this same problem.

Closes Faraday PR
-----------------

I'm going to recommend closing https://github.com/lostisland/faraday/pull/360/files
as the issue was probably introduced
[here](04a8514cba (diff-fc9726b31994223d11a212b5169100fdL68))
when `Response#finish` changed from storing the `env` directly,
to storing a copy:

```
- @env = env
+ @env = Env.from(env)
```

Presumably this behaviour is still desired, but the mentioned pull
essentially undoes this by returning the same `env` from `Env.from`

The commit that introduced the issue is probably good, but is called by
the app in the middleware stack that creates the response, before it
sets the rsponse onto the env. This means that the copy does not have
the link to the response.

81f16593a0/lib/faraday/rack_builder.rb (L152-155)

Not sure about the test name/location
-------------------------------------

I had difficulty figuring out where to put this test, and what to name
it. I eventually went with the test on the `middleware_stack_test.rb`,
because it deals with the `RackBuilder`, but if there's a better place,
or a better name, let me know and I'll update it.

One other weird thing
---------------------

Depending on when the `Request#on_complete` callback is invoked,
you're either getting the original env, or the copy:

81f16593a0/lib/faraday/response.rb (L64-65)
2015-05-05 00:52:04 -06:00
Pasha
01b434dbaf Make excon adapter compatible with 0.44 excon version 2015-03-14 03:07:30 +02:00
Alexander Pepper
c877521697 httpclient: Enable gzip compression.
Motivation: httpclient support gzip compression since late 2010 (see https://github.com/nahi/httpclient/issues/42 ).
2015-01-14 15:27:00 +01:00
risk danger olson
6262970390 Merge pull request #437 from deseretbook/add-retry-option-to-ignore-idempotent-methods
Allow specifying methods that bypass :retry_if on Request::Retry
2015-01-07 09:58:04 -07:00
Ben Maraney
7ea98de998 Version bump. 2015-01-04 10:22:31 +02:00
Ben Maraney
c2f325a329 NetHttp uses with_net_http_connection (#446) 2015-01-04 10:19:31 +02:00
Ruslan Korolev
baa537d89c clean constant IDEMPOTENT_METHODS 2014-11-26 15:58:03 +03:00
Mike Bourgeous
9ad0fcd38a Treat connection timeouts as connection failures in net-http adapter. 2014-11-13 17:41:48 -07:00
Mike Bourgeous
12fdb93ba8 Allow specifying the HTTP methods retried by Request::Retry. 2014-11-13 16:14:47 -07:00
Erik Michaels-Ober
ac7cc3a7bf Merge pull request #277 from stve/log_bodies
log request bodies in logger middleware
2014-10-05 19:22:32 +02:00
Mislav Marohnić
731f49039d Fix passing ActiveSupport::SafeBuffer to param encoders
Simply re-use `Faraday::Utils.escape/unescape` instead of reimplementing
them for each encoder.
2014-09-19 12:46:24 -06:00
James Smith
998d26cd62 Remove a remnant autoload require 2014-09-07 15:28:52 -07:00
James Smith
76c90bfdc0 Remove timeout from request autoloads, since it was removed in 43343e971f4bb9366daa1188272389166396a5c0 2014-09-06 18:05:26 -07:00
dtaniwaki
80c8b62de1 Fix interval_randomness data type 2014-09-01 17:51:27 +09:00
Alagu
6e37316372 Fix ActiveSupport::SafeBuffer#gsub bug
.. in NestedParamsEncoder
2014-06-06 14:03:32 +05:30
Janko Marohnić
edacd5eb57 Fix response not changing with parallel requests
In this order the @env would not be changed by the "on complete"
callbacks, meaning that the response would not change after parallel
requests finish (e.g. JSON would not be parsed).

This would work

  def on_complete(env)
    env[:body].upcase!
  end

But this wouldn't

  def on_complete(env)
    env[:body] = env[:body].upcase
  end
2014-05-23 14:03:39 +02:00
Ketan Padegaonkar
27d1fac7b1 Faraday::Utils::Headers#replace has side-effects
The headers hash contains some local state inside the @names instance variable as a means of doing case-insensitive hashes. This has the side-effect that one has to remember to perform mirror operations on the @names hash in addition to the object itself(Headers).

A case in point is the replace method – which did not clear out the @names hash which was causing side-effects by not performing a mirror operation (clear) on the @names hash.
2014-05-05 12:05:12 -03:00
Mauricio Linhares
ee6aba99be Retry only if the method is idempotent
Only run retries if the method is known to be
idempotent. If it isn't, switch to use the retry_if
block to make the final decision, if it is known to
be idempotent allow it to be retried by default.
2014-02-11 10:29:53 -03:00
Mauricio Linhares
65b5e8a440 Adds a retry_if option to the retry middleware
retry_if allows users to provide a block that
will receive the env and exception objects
and should decide if the call should be retried
or not.

Fixes #298.
2014-02-11 10:29:52 -03:00
Mislav Marohnić
4d0938343a Handle Patron "Connection time-out" properly 2014-02-11 13:01:01 +01:00
Erik Michaels-Ober
b8d90a59ba Release 0.9.0 2014-01-16 06:07:24 +01:00