Sha256: 06419dff1a7611b81eb52136c81d87f51ef911888653297f0ba99493ce014205

Contents?: true

Size: 667 Bytes

Versions: 5

Compression:

Stored size: 667 Bytes

Contents

##
# Patch HttpStreamingResponse
# in order to support webmocks and still use rack-proxy
#
# Inspired by @ehlertij commits on sportngin/rack-proxy:
# 616574e452fa731f5427d2ff2aff6823fcf28bde
# d8c377f7485997b229ced23c33cfef87d3fb8693
# 75b446a26ceb519ddc28f38b33309e9a2799074c
# 
module Rack
  class HttpStreamingResponse
    def each(&block)
      response.read_body(&block)
    ensure
      session.end_request_hacked unless mocking?
    end

    protected

    def response
      if mocking?
        @response ||= session.request(@request)
      else
        super
      end
    end

    def mocking?
      defined?(WebMock) || defined?(FakeWeb)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pact-provider-proxy-2.3.0 vendor/rack-reverse-proxy/spec/support/http_streaming_response_patch.rb
pact-provider-proxy-2.2.0 vendor/rack-reverse-proxy/spec/support/http_streaming_response_patch.rb
pact-provider-proxy-2.1.0 vendor/rack-reverse-proxy/spec/support/http_streaming_response_patch.rb
pact-provider-proxy-2.0.0 vendor/rack-reverse-proxy/spec/support/http_streaming_response_patch.rb
pact-provider-proxy-1.2.0 vendor/rack-reverse-proxy/spec/support/http_streaming_response_patch.rb