Sha256: 693d85f8777bae65dd245c89e20e98d953e3935bfbeedb0b26c2d45854870e54

Contents?: true

Size: 773 Bytes

Versions: 6

Compression:

Stored size: 773 Bytes

Contents

# frozen_string_literal: true

module HTTPX
  module Plugins
    #
    # This plugin adds support for stream response (text/event-stream).
    #
    module Stream
      module InstanceMethods
        def stream
          headers("accept" => "text/event-stream",
                  "cache-control" => "no-cache")
        end
      end

      module ResponseMethods
        def complete?
          super ||
            stream? &&
              @stream_complete
        end

        def stream?
          @headers["content-type"].start_with?("text/event-stream")
        end

        def <<(data)
          res = super
          @stream_complete = true if String(data).end_with?("\n\n")
          res
        end
      end
    end
    register_plugin :stream, Stream
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
httpx-0.9.0 lib/httpx/plugins/stream.rb
httpx-0.8.2 lib/httpx/plugins/stream.rb
httpx-0.8.1 lib/httpx/plugins/stream.rb
httpx-0.8.0 lib/httpx/plugins/stream.rb
httpx-0.7.0 lib/httpx/plugins/stream.rb
httpx-0.6.7 lib/httpx/plugins/stream.rb