blob: b23de5973772f3d8b3bb38ef6c017421bc59449b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# -*- frozen-string-literal: true -*-
using Plum::BinaryString
module Plum
class ServerConnection < Connection
def initialize(writer, local_settings = {})
super(writer, local_settings)
@state = :waiting_preface
end
# Reserves a new stream to server push.
# @param args [Hash] The argument to pass to Stram.new.
def reserve_stream(**args)
next_id = @max_stream_ids[0] + 2
stream = stream(next_id)
stream.set_state(:reserved_local)
stream.update_dependency(**args)
stream
end
private
def consume_buffer
if @state == :waiting_preface
negotiate!
end
super
end
def negotiate!
unless CLIENT_CONNECTION_PREFACE.start_with?(@buffer.byteslice(0, 24))
raise RemoteConnectionError.new(:protocol_error) # (MAY) send GOAWAY. sending.
end
if @buffer.bytesize >= 24
@buffer.byteshift(24)
settings(@local_settings)
@state = :waiting_settings
end
end
end
end
|