aboutsummaryrefslogtreecommitdiffstats
path: root/lib/plum
diff options
context:
space:
mode:
Diffstat (limited to 'lib/plum')
-rw-r--r--lib/plum/binary_string.rb2
-rw-r--r--lib/plum/client/client_session.rb13
-rw-r--r--lib/plum/client/decoders.rb16
-rw-r--r--lib/plum/client/legacy_client_session.rb10
-rw-r--r--lib/plum/connection.rb4
-rw-r--r--lib/plum/frame.rb4
-rw-r--r--lib/plum/rack/listener.rb12
-rw-r--r--lib/plum/rack/server.rb8
-rw-r--r--lib/plum/rack/thread_pool.rb4
-rw-r--r--lib/plum/server/http_connection.rb4
-rw-r--r--lib/plum/stream.rb4
11 files changed, 37 insertions, 44 deletions
diff --git a/lib/plum/binary_string.rb b/lib/plum/binary_string.rb
index 43051ef..02b417b 100644
--- a/lib/plum/binary_string.rb
+++ b/lib/plum/binary_string.rb
@@ -66,7 +66,7 @@ module Plum
end
else
Enumerator.new do |y|
- each_byteslice(n) {|ss| y << ss }
+ each_byteslice(n) { |ss| y << ss }
end
# I want to write `enum_for(__method__, n)`!
end
diff --git a/lib/plum/client/client_session.rb b/lib/plum/client/client_session.rb
index 81d2341..88cf15b 100644
--- a/lib/plum/client/client_session.rb
+++ b/lib/plum/client/client_session.rb
@@ -21,8 +21,9 @@ module Plum
def succ
@plum << @socket.readpartial(16384)
- rescue => e
- fail(e)
+ rescue
+ close
+ raise
end
def empty?
@@ -73,15 +74,11 @@ module Plum
end
private
- def fail(exception)
- close
- raise exception
- end
-
def setup_plum
plum = ClientConnection.new(@socket.method(:write), @http2_settings)
plum.on(:connection_error) { |ex|
- fail(ex)
+ close
+ raise ex
}
plum.window_update(@http2_settings[:initial_window_size])
plum
diff --git a/lib/plum/client/decoders.rb b/lib/plum/client/decoders.rb
index e6d72e7..d68f27b 100644
--- a/lib/plum/client/decoders.rb
+++ b/lib/plum/client/decoders.rb
@@ -17,14 +17,14 @@ module Plum
def decode(chunk)
@inflate.inflate(chunk)
- rescue Zlib::Error => e
- raise DecoderError.new("failed to decode chunk", e)
+ rescue Zlib::Error
+ raise DecoderError.new("failed to decode chunk", $!)
end
def finish
@inflate.finish
- rescue Zlib::Error => e
- raise DecoderError.new("failed to finalize", e)
+ rescue Zlib::Error
+ raise DecoderError.new("failed to finalize", $!)
end
end
@@ -35,14 +35,14 @@ module Plum
def decode(chunk)
@stream.inflate(chunk)
- rescue Zlib::Error => e
- raise DecoderError.new("failed to decode chunk", e)
+ rescue Zlib::Error
+ raise DecoderError.new("failed to decode chunk", $!)
end
def finish
@stream.finish
- rescue Zlib::Error => e
- raise DecoderError.new("failed to finalize", e)
+ rescue Zlib::Error
+ raise DecoderError.new("failed to finalize", $!)
end
end
diff --git a/lib/plum/client/legacy_client_session.rb b/lib/plum/client/legacy_client_session.rb
index a12f582..9dea6cd 100644
--- a/lib/plum/client/legacy_client_session.rb
+++ b/lib/plum/client/legacy_client_session.rb
@@ -16,8 +16,9 @@ module Plum
def succ
@parser << @socket.readpartial(16384)
- rescue => e # including HTTP::Parser::Error
- fail(e)
+ rescue # including HTTP::Parser::Error
+ close
+ raise
end
def empty?
@@ -47,11 +48,6 @@ module Plum
end
private
- def fail(exception)
- close
- raise exception
- end
-
def consume_queue
return if @response || @requests.empty?
diff --git a/lib/plum/connection.rb b/lib/plum/connection.rb
index 0268487..0ba5989 100644
--- a/lib/plum/connection.rb
+++ b/lib/plum/connection.rb
@@ -26,8 +26,8 @@ module Plum
def initialize(writer, local_settings = {})
@state = :open
@writer = writer
- @local_settings = Hash.new {|hash, key| DEFAULT_SETTINGS[key] }.merge!(local_settings)
- @remote_settings = Hash.new {|hash, key| DEFAULT_SETTINGS[key] }
+ @local_settings = Hash.new { |hash, key| DEFAULT_SETTINGS[key] }.merge!(local_settings)
+ @remote_settings = Hash.new { |hash, key| DEFAULT_SETTINGS[key] }
@buffer = String.new
@streams = {}
@hpack_decoder = HPACK::Decoder.new(@local_settings[:header_table_size])
diff --git a/lib/plum/frame.rb b/lib/plum/frame.rb
index 93f0a4c..bf61629 100644
--- a/lib/plum/frame.rb
+++ b/lib/plum/frame.rb
@@ -116,8 +116,8 @@ module Plum
def flags
fs = FRAME_FLAGS[type]
[0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80]
- .select {|v| @flags_value & v > 0 }
- .map {|val| fs && fs.key(val) || ("unknown_%02x" % val).to_sym }
+ .select { |v| @flags_value & v > 0 }
+ .map { |val| fs && fs.key(val) || ("unknown_%02x" % val).to_sym }
end
# Sets the frame flags.
diff --git a/lib/plum/rack/listener.rb b/lib/plum/rack/listener.rb
index ac60310..901642e 100644
--- a/lib/plum/rack/listener.rb
+++ b/lib/plum/rack/listener.rb
@@ -41,8 +41,8 @@ module Plum
sess = LegacySession.new(svc, e, sock)
sess.run
rescue Errno::ECONNRESET, Errno::ECONNABORTED, EOFError # closed
- rescue => e
- svc.log_exception(e)
+ rescue
+ svc.log_exception $!
ensure
sock.close
end
@@ -103,8 +103,8 @@ module Plum
sess = LegacySession.new(svc, e, sock)
sess.run
rescue Errno::ECONNRESET, Errno::ECONNABORTED, EOFError # closed
- rescue => e
- svc.log_exception(e)
+ rescue
+ svc.log_exception $!
ensure
sock.close if sock
end
@@ -172,8 +172,8 @@ module Plum
sess = Session.new(svc, sock, plum)
sess.run
rescue Errno::ECONNRESET, Errno::ECONNABORTED, EOFError # closed
- rescue => e
- svc.log_exception(e)
+ rescue
+ svc.log_exception $!
ensure
sock.close if sock
end
diff --git a/lib/plum/rack/server.rb b/lib/plum/rack/server.rb
index 3091246..5ab2e71 100644
--- a/lib/plum/rack/server.rb
+++ b/lib/plum/rack/server.rb
@@ -33,14 +33,14 @@ module Plum
begin
svr.accept(self)
rescue Errno::ECONNRESET, Errno::ECONNABORTED # closed
- rescue => e
- log_exception(e)
+ rescue
+ log_exception $!
end
}
end
rescue Errno::EBADF # closed
- rescue => e
- log_exception(e)
+ rescue
+ log_exception $!
end
end
#}
diff --git a/lib/plum/rack/thread_pool.rb b/lib/plum/rack/thread_pool.rb
index 45ee3ae..68ce2b6 100644
--- a/lib/plum/rack/thread_pool.rb
+++ b/lib/plum/rack/thread_pool.rb
@@ -24,8 +24,8 @@ module Plum
job, err = @jobs.pop
begin
job.call
- rescue => e
- err << e if err
+ rescue
+ err << $! if err
end
end
}
diff --git a/lib/plum/server/http_connection.rb b/lib/plum/server/http_connection.rb
index 0834379..b257137 100644
--- a/lib/plum/server/http_connection.rb
+++ b/lib/plum/server/http_connection.rb
@@ -26,7 +26,7 @@ module Plum
parser = HTTP::Parser.new
parser.on_headers_complete = proc { |_headers|
- headers = _headers.map {|n, v| [n.downcase, v] }.to_h
+ headers = _headers.map { |n, v| [n.downcase, v] }.to_h
}
parser.on_body = proc { |chunk| body << chunk }
parser.on_message_complete = proc { |env|
@@ -69,7 +69,7 @@ module Plum
nheaders = headers.merge({ ":method" => parser.http_method,
":path" => parser.request_url,
":authority" => headers["host"] })
- .reject {|n, v| ["connection", "http2-settings", "upgrade", "host"].include?(n) }
+ .reject { |n, v| ["connection", "http2-settings", "upgrade", "host"].include?(n) }
stream.receive_frame Frame.headers(1, encoder.encode(nheaders), end_headers: true)
stream.receive_frame Frame.data(1, body, end_stream: true)
diff --git a/lib/plum/stream.rb b/lib/plum/stream.rb
index 3cf3ba1..823a41a 100644
--- a/lib/plum/stream.rb
+++ b/lib/plum/stream.rb
@@ -156,8 +156,8 @@ module Plum
begin
decoded_headers = @connection.hpack_decoder.decode(payload)
- rescue => e
- raise RemoteConnectionError.new(:compression_error, e)
+ rescue
+ raise RemoteConnectionError.new(:compression_error, $!)
end
callback(:headers, decoded_headers)