Class: Stenohttp2::Server::StreamHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/stenohttp2/server/stream_handler.rb

Defined Under Namespace

Classes: Response

Instance Method Summary collapse

Constructor Details

#initialize(stream) ⇒ StreamHandler

Returns a new instance of StreamHandler.



5
6
7
# File 'lib/stenohttp2/server/stream_handler.rb', line 5

def initialize(stream)
  @stream = stream
end

Instance Method Details

#setupObject

rubocop:disable Metrics/AbcSize



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/stenohttp2/server/stream_handler.rb', line 10

def setup
  log = Stenohttp2::Common::Logger.new(stream.id)
  req = T.let({}, T.untyped)
  buffer = ''

  stream.on(:headers) do |h|
    req = Hash[*h.flatten]
    log.info "request headers: #{h}"
  end

  stream.on(:data) do |d|
    buffer << d
  end

  stream.on(:half_close) do
    log.info 'client closed its end of the stream... responding'
    response = Response.new(stream)
    response.build

    # Stream data to show this works
    stream.data(response.content[0...5], end_stream: false)
    stream.data(response.content[5...-1])
  end
end