diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2015-12-18 12:01:52 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2015-12-18 12:01:52 +0900 |
commit | 7b4297867c82e6e40f12be0d3d20f2ca12c8eed6 (patch) | |
tree | 3544caa2b3c9115c5cd1232a4351fe1bd7939233 | |
parent | 6becc12ef4e7235e749a92e3115b1155b39fc9e4 (diff) | |
download | plum-7b4297867c82e6e40f12be0d3d20f2ca12c8eed6.tar.gz |
drop Ruby 2.2 support
-rw-r--r-- | .travis.yml | 6 | ||||
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | circle.yml | 8 | ||||
-rw-r--r-- | lib/plum/event_emitter.rb | 10 | ||||
-rw-r--r-- | lib/plum/frame_factory.rb | 17 | ||||
-rw-r--r-- | lib/plum/hpack/context.rb | 15 | ||||
-rw-r--r-- | lib/plum/hpack/encoder.rb | 4 | ||||
-rw-r--r-- | lib/plum/rack/listener.rb | 2 | ||||
-rw-r--r-- | lib/plum/rack/session.rb | 2 | ||||
-rw-r--r-- | lib/plum/stream_utils.rb | 2 | ||||
-rw-r--r-- | test/plum/hpack/test_context.rb | 4 |
11 files changed, 35 insertions, 39 deletions
diff --git a/.travis.yml b/.travis.yml index 18ee383..468fb19 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,11 +4,11 @@ addons: repo_token: f5092ab344fac7f2de9d7332e00597642a4d24e3d560f7d7f329172a2e5a2def install: - echo openssl_url=https://www.openssl.org/source >> $rvm_path/user/db - - echo openssl_version=1.0.2d >> $rvm_path/user/db + - echo openssl_version=1.0.2e >> $rvm_path/user/db - rvm pkg install openssl - $rvm_path/usr/bin/openssl version - - rvm install 2.2.3-alpn --patch https://gist.githubusercontent.com/rhenium/b1711edcc903e8887a51/raw/2309e469f5a3ba15917d804ac61b19e62b3d8faf/ruby-openssl-alpn-no-tests-and-docs.patch --with-openssl-dir=$rvm_path/usr - - rvm use 2.2.3-alpn + - rvm install ruby-head --with-openssl-dir=$rvm_path/usr + - rvm use ruby-head - bundle install script: - bundle exec rake test @@ -6,9 +6,7 @@ WARNING: Plum is currently under heavy development. You *will* encounter bugs wh [![Circle CI](https://circleci.com/gh/rhenium/plum.svg?style=svg)](https://circleci.com/gh/rhenium/plum) [![Build Status](https://travis-ci.org/rhenium/plum.png?branch=master)](https://travis-ci.org/rhenium/plum) [![Code Climate](https://codeclimate.com/github/rhenium/plum/badges/gpa.svg)](https://codeclimate.com/github/rhenium/plum) [![Test Coverage](https://codeclimate.com/github/rhenium/plum/badges/coverage.svg)](https://codeclimate.com/github/rhenium/plum/coverage) ## Requirements -* Ruby - * Ruby 2.2 with [ALPN support patch](https://gist.github.com/rhenium/b1711edcc903e8887a51) and [ECDH support patch (r51348)](https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/51348/diff?format=diff) - * or latest Ruby 2.3.0-dev +* Ruby 2.3 * OpenSSL 1.0.2 or newer (HTTP/2 requires ALPN) * Optional: * [http_parser.rb gem](https://rubygems.org/gems/http_parser.rb) (HTTP/1.x parser; if you use "http" URI scheme) @@ -4,15 +4,15 @@ machine: dependencies: pre: - echo openssl_url=https://www.openssl.org/source >> $rvm_path/user/db - - echo openssl_version=1.0.2d >> $rvm_path/user/db + - echo openssl_version=1.0.2e >> $rvm_path/user/db - rvm pkg install openssl - > case $CIRCLE_NODE_INDEX in 0) - rvm install 2.2.3-alpn --with-openssl-dir=$rvm_path/usr --patch https://gist.githubusercontent.com/rhenium/b1711edcc903e8887a51/raw/2309e469f5a3ba15917d804ac61b19e62b3d8faf/ruby-openssl-alpn-no-tests-and-docs.patch - rvm use 2.2.3-alpn --default + rvm install ruby-2.3.0 --with-openssl-dir=$rvm_path/usr + rvm use ruby-2.3.0 --default ;; - 1) + 0) rvm install ruby-head --with-openssl-dir=$rvm_path/usr rvm use ruby-head --default ;; diff --git a/lib/plum/event_emitter.rb b/lib/plum/event_emitter.rb index 7bc9695..e0684dd 100644 --- a/lib/plum/event_emitter.rb +++ b/lib/plum/event_emitter.rb @@ -5,18 +5,14 @@ module Plum # @param name [Symbol] The name of event. # @yield Gives event-specific parameters. def on(name, &blk) - (callbacks[name] ||= []) << blk + @callbacks ||= {} + (@callbacks[name] ||= []) << blk end # Invokes an event and call handlers with args. # @param name [Symbol] The identifier of event. def callback(name, *args) - (cbs = callbacks[name]) && cbs.each {|cb| cb.call(*args) } - end - - private - def callbacks - @callbacks ||= {} + @callbacks&.[](name)&.each { |cb| cb.call(*args) } end end end diff --git a/lib/plum/frame_factory.rb b/lib/plum/frame_factory.rb index de5a0b4..b4919e5 100644 --- a/lib/plum/frame_factory.rb +++ b/lib/plum/frame_factory.rb @@ -17,7 +17,7 @@ module Plum # @param message [String] Additional debug data. # @see RFC 7540 Section 6.8 def goaway(last_id, error_type, message = "") - payload = String.new.push_uint32((last_id || 0) | (0 << 31)) + payload = String.new.push_uint32(last_id) .push_uint32(HTTPError::ERROR_CODES[error_type]) .push(message) Frame.new(type: :goaway, stream_id: 0, payload: payload) @@ -55,10 +55,9 @@ module Plum # @param stream_id [Integer] The stream ID. # @param payload [String] Payload. # @param end_stream [Boolean] add END_STREAM flag - def data(stream_id, payload, end_stream: false) - payload = payload.b if payload && payload.encoding != Encoding::BINARY - fval = 0 - fval += 1 if end_stream + def data(stream_id, payload = "", end_stream: false) + payload = payload.b if payload&.encoding != Encoding::BINARY + fval = end_stream ? 1 : 0 Frame.new(type_value: 0, stream_id: stream_id, flags_value: fval, payload: payload) end @@ -68,8 +67,7 @@ module Plum # @param end_stream [Boolean] add END_STREAM flag # @param end_headers [Boolean] add END_HEADERS flag def headers(stream_id, encoded, end_stream: false, end_headers: false) - fval = 0 - fval += 1 if end_stream + fval = end_stream ? 1 : 0 fval += 4 if end_headers Frame.new(type_value: 1, stream_id: stream_id, flags_value: fval, payload: encoded) end @@ -82,8 +80,7 @@ module Plum def push_promise(stream_id, new_id, encoded, end_headers: false) payload = String.new.push_uint32(new_id) .push(encoded) - fval = 0 - fval += 4 if end_headers + fval = end_headers ? 4 : 0 Frame.new(type: :push_promise, stream_id: stream_id, flags_value: fval, payload: payload) end @@ -92,7 +89,7 @@ module Plum # @param payload [String] Payload. # @param end_headers [Boolean] add END_HEADERS flag def continuation(stream_id, payload, end_headers: false) - Frame.new(type: :continuation, stream_id: stream_id, flags_value: (end_headers && 4 || 0), payload: payload) + Frame.new(type: :continuation, stream_id: stream_id, flags_value: (end_headers ? 4 : 0), payload: payload) end end end diff --git a/lib/plum/hpack/context.rb b/lib/plum/hpack/context.rb index 1d7f7d6..86dc244 100644 --- a/lib/plum/hpack/context.rb +++ b/lib/plum/hpack/context.rb @@ -36,18 +36,21 @@ module Plum end def search(name, value) - pr = proc { |n, v| - n == name && (!value || v == value) - } + si = STATIC_TABLE.index { |n, v| n == name && v == value } + return si + 1 if si + di = @dynamic_table.index { |n, v| n == name && v == value } + return di + STATIC_TABLE_SIZE + 1 if di + end - si = STATIC_TABLE.index &pr + def search_half(name) + si = STATIC_TABLE.index { |n, v| n == name } return si + 1 if si - di = @dynamic_table.index &pr + di = @dynamic_table.index { |n, v| n == name } return di + STATIC_TABLE_SIZE + 1 if di end def evict - while @limit && @size > @limit + while @size > @limit name, value = @dynamic_table.pop @size -= name.bytesize + value.bytesize + 32 end diff --git a/lib/plum/hpack/encoder.rb b/lib/plum/hpack/encoder.rb index d817589..2653c5b 100644 --- a/lib/plum/hpack/encoder.rb +++ b/lib/plum/hpack/encoder.rb @@ -12,13 +12,13 @@ module Plum @huffman = huffman end def encode(headers) - out = String.new.force_encoding(Encoding::BINARY) + out = "".b headers.each do |name, value| name = name.to_s value = value.to_s if index = search(name, value) out << encode_indexed(index) - elsif index = search(name, nil) + elsif index = search_half(name) out << encode_half_indexed(index, value) else out << encode_literal(name, value) diff --git a/lib/plum/rack/listener.rb b/lib/plum/rack/listener.rb index 4b8fd45..bc29e5b 100644 --- a/lib/plum/rack/listener.rb +++ b/lib/plum/rack/listener.rb @@ -46,7 +46,7 @@ module Plum *ctx.extra_chain_cert, ctx.cert = parse_chained_cert(cert) ctx.key = OpenSSL::PKey::RSA.new(key) ctx.servername_cb = proc { |sock, hostname| - if lc[:sni] && (host = lc[:sni][hostname]) + if host = lc[:sni]&.[](hostname) new_ctx = ctx.dup *new_ctx.extra_chain_cert, new_ctx.cert = parse_chained_cert(File.read(host[:certificate])) new_ctx.key = OpenSSL::PKey::RSA.new(File.read(host[:certificate_key])) diff --git a/lib/plum/rack/session.rb b/lib/plum/rack/session.rb index 24830d3..151a2f0 100644 --- a/lib/plum/rack/session.rb +++ b/lib/plum/rack/session.rb @@ -83,7 +83,7 @@ module Plum end else body.each { |part| stream.send_data(part, end_stream: false) } - stream.send_data(nil, end_stream: true) + stream.send_data(end_stream: true) end ensure body.close if body.respond_to?(:close) diff --git a/lib/plum/stream_utils.rb b/lib/plum/stream_utils.rb index dbb8d96..5fd6cc2 100644 --- a/lib/plum/stream_utils.rb +++ b/lib/plum/stream_utils.rb @@ -28,7 +28,7 @@ module Plum # 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) + def send_data(data = "", end_stream: true) max = @connection.remote_settings[:max_frame_size] if data.is_a?(IO) until data.eof? diff --git a/test/plum/hpack/test_context.rb b/test/plum/hpack/test_context.rb index 3b662ec..4a54e6c 100644 --- a/test/plum/hpack/test_context.rb +++ b/test/plum/hpack/test_context.rb @@ -38,6 +38,8 @@ class HPACKContextTest < Minitest::Test context = new_context i1 = context.search(":method", "POST") assert_equal(3, i1) + i2 = context.search_half(":method") + assert_equal(2, i2) end def test_search_dynamic @@ -48,7 +50,7 @@ class HPACKContextTest < Minitest::Test assert_equal(63, i1) i2 = context.search("あああ", "AAA") assert_equal(nil, i2) - i3 = context.search("あああ", nil) + i3 = context.search_half("あああ") assert_equal(62, i3) end |