Class: Faraday::Adapter::FuryHttp

Inherits:
NetHttp
  • Object
show all
Defined in:
lib/faraday/adapter/fury_http.rb

Instance Method Summary collapse

Instance Method Details

#perform_request(http, env) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/faraday/adapter/fury_http.rb', line 6

def perform_request(http, env)
  accept = env.request_headers['Accept']
  return super if accept !~ /text\z/

  # Stream response body to STDOUT on success
  http.request(create_request(env)) do |resp|
    unless resp.is_a?(Net::HTTPSuccess)
      resp.body # Cache error body
    else
      resp.read_body do |chunk|
        $stdout.print(chunk)
        $stdout.flush
      end

      # Prevent #body from calling #read_body again
      klass = (class << resp; self; end)
      klass.send(:define_method, :body) { nil }
    end

    # Return response to NetHttp adapter
    return resp
  end
end