Sha256: 3492407efad7e393d64f5bc903ead298f60c532e4b4fedc6ba0529e052c7949e

Contents?: true

Size: 633 Bytes

Versions: 2

Compression:

Stored size: 633 Bytes

Contents

# frozen_string_literal: true

# 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 request_with_wrapped_block(http, env, &block)
      is_text = env.request_headers['Accept'] =~ /text\z/
      return super if !block.nil? || !is_text

      # Stream chunks directly to STDOUT
      resp = super(http, env) do |chunk|
        $stdout.print(chunk)
        $stdout.flush
      end

      # Client sees nil body
      resp.body = nil
      resp
    end
  end

  register_middleware(fury_http: FuryHttp)
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gemfury-0.13.0 lib/faraday/adapter/fury_http.rb
gemfury-0.13.0.beta1 lib/faraday/adapter/fury_http.rb