lib/faraday/adapter/net_http.rb in faraday-0.7.5 vs lib/faraday/adapter/net_http.rb in faraday-0.7.6

- old
+ new

@@ -15,12 +15,11 @@ http = net_http_class(env).new(url.host, url.inferred_port) if http.use_ssl = (url.scheme == 'https' && (ssl = env[:ssl]) && true) http.verify_mode = ssl[:verify_mode] || begin - if ssl.fetch(:verify, true) - OpenSSL::SSL::VERIFY_PEER + if ssl.fetch(:verify, true) # Use the default cert store by default, i.e. system ca certs store = OpenSSL::X509::Store.new store.set_default_paths http.cert_store = store OpenSSL::SSL::VERIFY_PEER @@ -38,26 +37,26 @@ end http.read_timeout = http.open_timeout = req[:timeout] if req[:timeout] http.open_timeout = req[:open_timeout] if req[:open_timeout] - if :get != env[:method] + if :get != env[:method] or env[:body] http_request = Net::HTTPGenericRequest.new \ env[:method].to_s.upcase, # request method - !!env[:body], # is there data - true, # does net/http love you, true or false? + !!env[:body], # is there request body + :head != env[:method], # is there response body url.request_uri, # request uri path env[:request_headers] # request headers if env[:body].respond_to?(:read) http_request.body_stream = env[:body] env[:body] = nil end end begin - http_response = if :get == env[:method] + http_response = if :get == env[:method] and env[:body].nil? # prefer `get` to `request` because the former handles gzip (ruby 1.9) http.get url.request_uri, env[:request_headers] else http.request http_request, env[:body] end @@ -70,9 +69,11 @@ response_headers[key] = value end end @app.call env + rescue Timeout::Error => err + raise Faraday::Error::TimeoutError, err end def net_http_class(env) if proxy = env[:request][:proxy] Net::HTTP::Proxy(proxy[:uri].host, proxy[:uri].port, proxy[:user], proxy[:password])