Class: Rack::Stream::Handlers::Http

Inherits:
AbstractHandler show all
Defined in:
lib/rack/stream/handlers/http.rb

Overview

This Handler works under EventMachine aware Rack servers like Thin and Rainbows! It does chunked transfer encoding.

Constant Summary collapse

TERM =
"\r\n".freeze
TAIL =
"0#{TERM}#{TERM}".freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractHandler

#initialize

Constructor Details

This class inherits a constructor from Rack::Stream::Handlers::AbstractHandler

Class Method Details

.accepts?(app) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/rack/stream/handlers/http.rb', line 10

def self.accepts?(app)
  true
end

Instance Method Details

#chunk(*chunks) ⇒ Object



14
15
16
# File 'lib/rack/stream/handlers/http.rb', line 14

def chunk(*chunks)
  super(*chunks.map {|c| encode_chunk(c)})
end

#closeObject



23
24
25
# File 'lib/rack/stream/handlers/http.rb', line 23

def close
  @body.chunk(TAIL)  # tail is special and already encoded
end

#openObject



18
19
20
21
# File 'lib/rack/stream/handlers/http.rb', line 18

def open
  @app.headers['Transfer-Encoding'] = 'chunked'
  @app.env['async.callback'].call [@app.status, @app.headers, @body]
end