Class: Protocol::HTTP2::Client

Inherits:
Connection show all
Defined in:
lib/protocol/http2/client.rb

Instance Attribute Summary

Attributes inherited from Connection

#framer, #local_settings, #local_window, #remote_settings, #remote_window, #state, #streams

Instance Method Summary collapse

Methods inherited from Connection

#accept_stream, #close, #closed?, #connection_error!, #create_stream, #decode_headers, #encode_headers, #id, #maximum_concurrent_streams, #maximum_frame_size, #next_stream_id, #open!, #process_settings, #read_frame, #receive_continuation, #receive_data, #receive_frame, #receive_goaway, #receive_headers, #receive_ping, #receive_priority, #receive_reset_stream, #receive_settings, #receive_window_update, #send_goaway, #send_ping, #send_settings, #update_local_settings, #update_remote_settings, #window_updated, #write_frame

Methods included from FlowControl

#available_frame_size, #consume_local_window, #consume_remote_window, #receive_window_update, #send_window_update, #window_updated

Constructor Details

#initialize(framer) ⇒ Client

Returns a new instance of Client.



26
27
28
# File 'lib/protocol/http2/client.rb', line 26

def initialize(framer)
	super(framer, 1)
end

Instance Method Details

#accept_push_promise_stream(stream_id, &block) ⇒ Object

Accept an incoming push promise from the other side of the connection. On the client side, we accept push promise streams. On the server side, streams create push promise streams.



53
54
55
# File 'lib/protocol/http2/client.rb', line 53

def accept_push_promise_stream(stream_id, &block)
	accept_stream(stream_id, &block)
end

#create_push_promise_streamObject

Raises:



57
58
59
# File 'lib/protocol/http2/client.rb', line 57

def create_push_promise_stream
	raise ProtocolError, "Cannot create push promises from client!"
end

#receive_push_promise(frame) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/protocol/http2/client.rb', line 61

def receive_push_promise(frame)
	if frame.stream_id == 0
		raise ProtocolError, "Cannot receive headers for stream 0!"
	end
	
	if stream = @streams[frame.stream_id]
		# This is almost certainly invalid:
		promised_stream, request_headers = stream.receive_push_promise(frame)
		
		if stream.closed?
			@streams.delete(stream.id)
		end
		
		return promised_stream, request_headers
	end
end

#send_connection_preface(settings = []) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/protocol/http2/client.rb', line 34

def send_connection_preface(settings = [])
	if @state == :new
		@framer.write_connection_preface
		
		send_settings(settings)
		
		yield if block_given?
		
		read_frame do |frame|
			raise ProtocolError, "First frame must be SettingsFrame, but got #{frame.class}" unless frame.is_a? SettingsFrame
		end
	else
		raise ProtocolError, "Cannot send connection preface in state #{@state}"
	end
end

#valid_remote_stream_id?(stream_id) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/protocol/http2/client.rb', line 30

def valid_remote_stream_id?(stream_id)
	stream_id.even?
end