use net/http by default if no middleware is set

This commit is contained in:
rick 2010-04-27 10:03:13 -04:00
parent a43e0896a6
commit 6220abd088
4 changed files with 26 additions and 4 deletions

View File

@ -1,6 +1,12 @@
require 'rack/utils'
module Faraday
class << self
attr_accessor :default_adapter
end
self.default_adapter = :net_http
module AutoloadHelper
def register_lookup_modules(mods)
(@lookup_module_index ||= {}).update(mods)

View File

@ -24,7 +24,10 @@ module Faraday
build(&block) if block_given?
end
def build(&block)
def build(options = {}, &block)
if options[:reset]
@handlers.clear
end
block.call(self)
run(self.class.inner_app)
end
@ -39,6 +42,10 @@ module Faraday
end
def to_app
if @handlers.empty?
build { |b| b.adapter Faraday.default_adapter }
end
inner_app = @handlers.first
@handlers[1..-1].inject(inner_app) { |app, middleware| middleware.call(app) }
end

View File

@ -44,8 +44,8 @@ module Faraday
end
end
def build(&block)
@builder.build(&block)
def build(options = {}, &block)
@builder.build(options, &block)
end
def get(url = nil, headers = nil, &block)

View File

@ -218,4 +218,13 @@ class TestConnection < Faraday::TestCase
assert_not_equal conn.send(attr).object_id, duped.send(attr).object_id
end
end
end
def test_sets_default_adapter_if_none_set
conn = Faraday::Connection.new
assert_equal 0, conn.builder.handlers.size
app = conn.to_app
mware = conn.builder.handlers[1].call({})
assert_kind_of Faraday::Adapter::NetHttp, mware
end
end