From 36f04dd04263cc3fe97a8bdfd3dbd84c4e813d12 Mon Sep 17 00:00:00 2001 From: Kazuki Yamaguchi Date: Mon, 19 Oct 2015 22:17:52 +0900 Subject: stream_utils: make Stream#send_data and Stream#send_headers public --- lib/plum/stream_utils.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/plum/stream_utils.rb b/lib/plum/stream_utils.rb index 0bcceec..44ed945 100644 --- a/lib/plum/stream_utils.rb +++ b/lib/plum/stream_utils.rb @@ -2,9 +2,9 @@ using Plum::BinaryString module Plum module StreamUtils - # Responds to HTTP request. + # Responds to a HTTP request. # - # @param headers [Hash] The response headers. + # @param headers [Enumerable] The response headers. # @param body [String, IO] The response body. def respond(headers, body = nil, end_stream: true) # TODO: priority, padding if body @@ -17,7 +17,7 @@ module Plum # Reserves a stream to server push. Sends PUSH_PROMISE and create new stream. # - # @param headers [Hash] The *request* headers. It must contain all of them: ':authority', ':method', ':scheme' and ':path'. + # @param headers [Enumerable] The *request* headers. It must contain all of them: ':authority', ':method', ':scheme' and ':path'. # @return [Stream] The stream to send push response. def promise(headers) stream = @connection.reserve_stream(weight: self.weight + 1, parent: self) @@ -29,7 +29,10 @@ module Plum stream end - private + # Sends response headers. If the encoded frame is larger than MAX_FRAME_SIZE, the headers will be splitted into HEADERS frame and CONTINUATION frame(s). + # + # @param headers [Enumerable] The response headers. + # @param end_stream [Boolean] Set END_STREAM flag or not. def send_headers(headers, end_stream:) max = @connection.remote_settings[:max_frame_size] encoded = @connection.hpack_encoder.encode(headers) @@ -40,6 +43,10 @@ module Plum @state = :half_closed_local if end_stream end + # Sends DATA frame. If the data is larger than MAX_FRAME_SIZE, DATA frame will be splitted. + # + # @param data [String, IO] The data to send. + # @param end_stream [Boolean] Set END_STREAM flag or not. def send_data(data, end_stream: true) max = @connection.remote_settings[:max_frame_size] if data.is_a?(IO) -- cgit v1.2.3