vcr/vcr — pull request #356 by myronmarston (2013-11-12 07:51:42+00:00)
Title: Fix for excon idempotent retries

@geemus -- I ran into a case where VCR wasn't recording responses properly due to the ordering semantics of Excon middlewares stack. I've found a solution by splitting VCR's middleware into two pieces that are injected into the middleware stack at separate spots. I wanted to run this by you and confirm that some assumptions I'm making here are intended public behaviors of Excon and not private implementation details that you may change. Here's how I'm injecting my middleware:

``` ruby
middlewares = ::Excon.defaults[:middlewares]

middlewares << VCR::Middleware::Excon::Request
response_parser_index = middlewares.index(::Excon::Middleware::ResponseParser)
middlewares.insert(response_parser_index + 1, VCR::Middleware::Excon::Response)
```

* Is it correct to assume that middlewares appended on the end of the list will always get its `request_call` method called last in the chain before the request is sent out over the wire? VCR needs to intercept the request just before it is made, after all other middlewares have had a chance to do whatever they want with the request.
* Given that VCR needs access to the response as early as possible, before other middlewares have had a chance to mutate it (or raise errors based on it), is it best to search for the index of `Excon::Middleware::ResponseParser` and then insert my response middleware after it?