Sha256: 0c8fc490478b27091cd5c93ce1c9055f2b9133b8c6b4cf1de738f5578a398b68

Contents?: true

Size: 651 Bytes

Versions: 49

Compression:

Stored size: 651 Bytes

Contents

use Rack::ContentType, "text/plain"

app = lambda do |env|
  # streamed pieces to be sent
  pieces = %w{Hello streamy world}

  response_headers = {}

  # set a fixed content length in the header if requested
  if env['REQUEST_PATH'] == '/streamed/fixed_length'
    response_headers['Content-Length'] = pieces.join.length.to_s
  end

  response_headers["rack.hijack"] = lambda do |io|
    # Write directly to IO of the response
    begin
      # return the response in pieces
      pieces.each do |x|
        sleep(0.1)
        io.write(x)
        io.flush
      end
    ensure
      io.close
    end
  end
  [200, response_headers, nil]
end

run app

Version data entries

49 entries across 47 versions & 4 rubygems

Version Path
excon-0.64.0 tests/rackups/streaming.ru
excon-0.63.0 tests/rackups/streaming.ru
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/excon-0.62.0/tests/rackups/streaming.ru
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/excon-0.62.0/tests/rackups/streaming.ru
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/excon-0.62.0/tests/rackups/streaming.ru
excon-0.62.0 tests/rackups/streaming.ru
excon-0.61.0 tests/rackups/streaming.ru
excon-0.60.0 tests/rackups/streaming.ru
excon-0.59.0 tests/rackups/streaming.ru
excon-0.58.0 tests/rackups/streaming.ru
excon-0.57.1 tests/rackups/streaming.ru
excon-0.57.0 tests/rackups/streaming.ru
excon-0.56.0 tests/rackups/streaming.ru
excon-0.55.0 tests/rackups/streaming.ru
excon-0.54.0 tests/rackups/streaming.ru
excon-0.53.0 tests/rackups/streaming.ru
excon-0.52.0 tests/rackups/streaming.ru
excon-0.51.0 tests/rackups/streaming.ru
excon-0.50.1 tests/rackups/streaming.ru
excon-0.50.0 tests/rackups/streaming.ru