Sha256: b0d5f8e5f72b06c85176fdb173cf563d80008cc9ad7ddf565f5c18ae21509622

Contents?: true

Size: 689 Bytes

Versions: 21

Compression:

Stored size: 689 Bytes

Contents

# frozen_string_literal: true

module HTTPX
  module Plugins
    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

21 entries across 21 versions & 1 rubygems

Version Path
httpx-0.6.6 lib/httpx/plugins/stream.rb
httpx-0.6.5 lib/httpx/plugins/stream.rb
httpx-0.6.4 lib/httpx/plugins/stream.rb
httpx-0.6.3 lib/httpx/plugins/stream.rb
httpx-0.6.2 lib/httpx/plugins/stream.rb
httpx-0.6.1 lib/httpx/plugins/stream.rb
httpx-0.6.0 lib/httpx/plugins/stream.rb
httpx-0.5.1 lib/httpx/plugins/stream.rb
httpx-0.5.0 lib/httpx/plugins/stream.rb
httpx-0.4.1 lib/httpx/plugins/stream.rb
httpx-0.4.0 lib/httpx/plugins/stream.rb
httpx-0.3.1 lib/httpx/plugins/stream.rb
httpx-0.3.0 lib/httpx/plugins/stream.rb
httpx-0.2.1 lib/httpx/plugins/stream.rb
httpx-0.2.0 lib/httpx/plugins/stream.rb
httpx-0.1.0 lib/httpx/plugins/stream.rb
httpx-0.0.5 lib/httpx/plugins/stream.rb
httpx-0.0.4 lib/httpx/plugins/stream.rb
httpx-0.0.3 lib/httpx/plugins/stream.rb
httpx-0.0.2 lib/httpx/plugins/stream.rb