diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2015-07-20 08:26:43 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2015-07-20 08:26:43 +0900 |
commit | df90697ece07c47f810832026c9764c1163b24c2 (patch) | |
tree | 02c2f05cd41ec3f0fe5c3451e533a93823805642 | |
parent | 059fd19049ad77bf4ff7c61ba3b7a5b65c8ee206 (diff) | |
download | plum-df90697ece07c47f810832026c9764c1163b24c2.tar.gz |
stream: check stream status on sending frame
-rw-r--r-- | lib/plum/stream.rb | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/lib/plum/stream.rb b/lib/plum/stream.rb index 824114a..a85b396 100644 --- a/lib/plum/stream.rb +++ b/lib/plum/stream.rb @@ -33,7 +33,7 @@ module Plum if frame.flags.include?(:end_stream) # :data, :headers callback(:complete) - @state = :half_closed + @state = :half_closed_remote end rescue Plum::StreamError => e callback(:stream_error, e) @@ -44,6 +44,31 @@ module Plum end def send(frame) + case @state + when :idle + # BUG? + unless [:headers, :priority].include?(frame.type) + raise Error.new("can't send frames other than HEADERS or PRIORITY on an idle stream") + end + when :reserved_local + unless [:headers, :rst_stream].include?(frame.type) + raise Error.new("can't send frames other than HEADERS or RST_STREAM on a reserved (local) stream") + end + when :reserved_remote + unless [:priority, :window_update, :rst_stream].include?(frame.type) + raise Error.new("can't send frames other than PRIORITY, WINDOW_UPDATE or RST_STREAM on a reserved (remote) stream") + end + when :half_closed_local + unless [:window_update, :priority, :rst_stream].include?(frame.type) + raise Error.new("can't send frames other than WINDOW_UPDATE, PRIORITY and RST_STREAM on a half-closed (local) stream") + end + when :closed + unless [:priority].include?(frame.type) + raise Error.new("can't send frames other than PRIORITY on a closed stream") + end + when :half_closed_remote, :open + # open! + end @connection.send(frame) end @@ -54,6 +79,7 @@ module Plum else send_headers(headers, end_stream: end_stream) end + @state = :half_closed_local if end_stream end def promise(headers) # TODO: fragment |