Sha256: 810ddbde44c56e8ccac981ab271879d5c3bc40bc529b7e3b28787fe8049a9680
Contents?: true
Size: 909 Bytes
Versions: 15
Compression:
Stored size: 909 Bytes
Contents
# This is a Faraday adapter that bypasses Faraday's response body # processing and streams body to STDOUT for text requests class Faraday::Adapter class FuryHttp < NetHttp 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 end register_middleware(:fury_http => FuryHttp) end
Version data entries
15 entries across 15 versions & 1 rubygems