aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2015-11-16 18:17:44 +0900
committerKazuki Yamaguchi <k@rhe.jp>2015-11-16 18:17:44 +0900
commitcae4777e2da251aeb9a8377cb19f65fa2b2e757b (patch)
treeeaf67f79648d0fdd8b96879883a4623eaef28fa8
parent26fc2766cf36abc9cee4075f8ce1a5dc0f222998 (diff)
downloadplum-cae4777e2da251aeb9a8377cb19f65fa2b2e757b.tar.gz
stream: don't raise LocalStreamError when received RST_STREAM but callback :rst_stream
-rw-r--r--lib/plum/client/client_session.rb4
-rw-r--r--lib/plum/connection_utils.rb4
-rw-r--r--lib/plum/rack/cli.rb2
-rw-r--r--lib/plum/rack/session.rb4
-rw-r--r--lib/plum/stream.rb6
-rw-r--r--test/plum/test_stream.rb11
6 files changed, 14 insertions, 17 deletions
diff --git a/lib/plum/client/client_session.rb b/lib/plum/client/client_session.rb
index 6e9fc56..09539aa 100644
--- a/lib/plum/client/client_session.rb
+++ b/lib/plum/client/client_session.rb
@@ -64,6 +64,10 @@ module Plum
response._fail
raise ex
}
+ stream.on(:local_stream_error) { |type|
+ response.fail
+ raise LocalStreamError.new(type)
+ }
response
end
diff --git a/lib/plum/connection_utils.rb b/lib/plum/connection_utils.rb
index ba8acbd..4d06594 100644
--- a/lib/plum/connection_utils.rb
+++ b/lib/plum/connection_utils.rb
@@ -19,9 +19,9 @@ module Plum
# Sends GOAWAY frame to the peer and closes the connection.
# @param error_type [Symbol] The error type to be contained in the GOAWAY frame.
- def goaway(error_type = :no_error)
+ def goaway(error_type = :no_error, message = "")
last_id = @max_stream_ids.max
- send_immediately Frame.goaway(last_id, error_type)
+ send_immediately Frame.goaway(last_id, error_type, message)
end
# Returns whether peer enables server push or not
diff --git a/lib/plum/rack/cli.rb b/lib/plum/rack/cli.rb
index 635a138..3ee50fe 100644
--- a/lib/plum/rack/cli.rb
+++ b/lib/plum/rack/cli.rb
@@ -35,7 +35,7 @@ module Plum
def transform_options
if @options[:config]
- dsl = DSL::Config.new.instance_eval(File.read(@options[:config]))
+ dsl = DSL::Config.new.tap { |c| c.instance_eval(File.read(@options[:config])) }
config = dsl.config
else
config = Config.new
diff --git a/lib/plum/rack/session.rb b/lib/plum/rack/session.rb
index 76e91c0..f95a10f 100644
--- a/lib/plum/rack/session.rb
+++ b/lib/plum/rack/session.rb
@@ -38,10 +38,6 @@ module Plum
private
def setup_plum
- @plum.on(:frame) { |f| puts "recv:#{f.inspect}" }
- @plum.on(:send_frame) { |f|
- puts "send:#{f.inspect}" unless f.type == :data
- }
@plum.on(:connection_error) { |ex| @logger.error(ex) }
# @plum.on(:stream) { |stream| @logger.debug("new stream: #{stream}") }
diff --git a/lib/plum/stream.rb b/lib/plum/stream.rb
index 04190fc..4cb2285 100644
--- a/lib/plum/stream.rb
+++ b/lib/plum/stream.rb
@@ -237,11 +237,7 @@ module Plum
@state = :closed # MUST NOT send RST_STREAM
error_code = frame.payload.uint32
- if error_code > 0
- raise LocalStreamError.new(HTTPError::ERROR_CODES.key(error_code))
- else
- callback(:rst_stream, frame)
- end
+ callback(:rst_stream, HTTPError::ERROR_CODES.key(error_code))
end
# override EventEmitter
diff --git a/test/plum/test_stream.rb b/test/plum/test_stream.rb
index 9b06214..2ed3ac9 100644
--- a/test/plum/test_stream.rb
+++ b/test/plum/test_stream.rb
@@ -40,13 +40,14 @@ class StreamTest < Minitest::Test
def test_stream_local_error
open_server_connection { |con|
- stream = nil
- con.on(:headers) { |s| stream = s }
+ stream = type = nil
+ con.on(:rst_stream) { |s, t| stream = s; type = t }
con << Frame.headers(1, "", end_headers: true).assemble
- assert_raises(LocalStreamError) {
- con << Frame.rst_stream(1, :frame_size_error).assemble
- }
+ con << Frame.rst_stream(1, :frame_size_error).assemble
+
+ assert_equal(1, stream.id)
+ assert_equal(:frame_size_error, type)
}
end
end