-
Notifications
You must be signed in to change notification settings - Fork 972
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* They're now final endpoints. They don't call `@app.call` anymore. * Env refactoring * Refactors `Env` by moving all response-related fields into the response. The response body doesn't override the request body anymore! * Ensures backwards compatibility by introducing getter methods in `Env`. * Middlewares refactoring (mostly backwards compatible): * All middlewares inherit from the same `Faraday::Middleware` class. * Adds new `on_request` helper so basic middlewares (request and response) don't need to override `call` anymore. * Refactor existing middlewares to reflect this change. * Updates UPGRADING.md with all breaking changes. Fixes #47 once and for all! Fixes #517
- Loading branch information
Showing
40 changed files
with
504 additions
and
450 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,58 @@ | ||
module Faraday | ||
# Base class for all Faraday adapters. Adapters are | ||
# responsible for fulfilling a Faraday request. | ||
class Adapter < Middleware | ||
class Adapter | ||
extend MiddlewareRegistry | ||
extend DependencyLoader | ||
|
||
CONTENT_LENGTH = 'Content-Length'.freeze | ||
|
||
register_middleware File.expand_path('../adapter', __FILE__), | ||
:test => [:Test, 'test'], | ||
:net_http => [:NetHttp, 'net_http'], | ||
:net_http_persistent => [:NetHttpPersistent, 'net_http_persistent'], | ||
:typhoeus => [:Typhoeus, 'typhoeus'], | ||
:patron => [:Patron, 'patron'], | ||
:em_synchrony => [:EMSynchrony, 'em_synchrony'], | ||
:em_http => [:EMHttp, 'em_http'], | ||
:excon => [:Excon, 'excon'], | ||
:rack => [:Rack, 'rack'], | ||
:httpclient => [:HTTPClient, 'httpclient'] | ||
:test => [:Test, 'test'], | ||
:net_http => [:NetHttp, 'net_http'], | ||
:net_http_persistent => [:NetHttpPersistent, 'net_http_persistent'], | ||
:typhoeus => [:Typhoeus, 'typhoeus'], | ||
:patron => [:Patron, 'patron'], | ||
:em_synchrony => [:EMSynchrony, 'em_synchrony'], | ||
:em_http => [:EMHttp, 'em_http'], | ||
:excon => [:Excon, 'excon'], | ||
:rack => [:Rack, 'rack'], | ||
:httpclient => [:HTTPClient, 'httpclient'] | ||
|
||
# This module marks an Adapter as supporting parallel requests. | ||
module Parallelism | ||
attr_writer :supports_parallel | ||
def supports_parallel?() @supports_parallel end | ||
|
||
def supports_parallel?() | ||
@supports_parallel | ||
end | ||
|
||
def inherited(subclass) | ||
super | ||
subclass.supports_parallel = self.supports_parallel? | ||
end | ||
end | ||
|
||
extend Parallelism | ||
self.supports_parallel = false | ||
|
||
def initialize(app = nil, opts = {}, &block) | ||
super(app) | ||
def initialize(opts = {}, &block) | ||
@app = lambda { |env| env.response } | ||
@connection_options = opts | ||
@config_block = block | ||
end | ||
|
||
def call(env) | ||
env.clear_body if env.needs_body? | ||
env.response ||= Response.new | ||
end | ||
|
||
private | ||
|
||
def save_response(env, status, body, headers = nil, reason_phrase = nil) | ||
env.status = status | ||
env.body = body | ||
env.reason_phrase = reason_phrase && reason_phrase.to_s.strip | ||
env.response_headers = Utils::Headers.new.tap do |response_headers| | ||
response_headers.update headers unless headers.nil? | ||
yield(response_headers) if block_given? | ||
end | ||
params = { status: status, body: body, headers: headers, reason_phrase: reason_phrase&.to_s&.strip } | ||
env.parallel? ? env.response.apply_params(params) : env.response.finish(params) | ||
yield(env.response.headers) if block_given? | ||
env.response | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.