Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/http/2/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,8 @@ def connection_management(frame)
when :closed
case frame_type
when :goaway
connection_error
# 6.8. GOAWAY
# An endpoint MAY send multiple GOAWAY frames if circumstances change.
when :ping
ping_management(frame)
else
Expand Down
2 changes: 1 addition & 1 deletion lib/http/2/extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def append_str(str, data)
def read_str(str, n)
return "".b if n == 0

chunk = str.byteslice(0..n - 1)
chunk = str.byteslice(0..(n - 1))
remaining = str.byteslice(n..-1)
remaining ? str.replace(remaining) : str.clear
chunk
Expand Down
4 changes: 2 additions & 2 deletions lib/http/2/framer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def read_common_header(buf)
{
type: type,
flags: FRAME_FLAGS[type].filter_map do |name, pos|
name if flags.anybits?((1 << pos))
name if flags.anybits?(1 << pos)
end,
length: length,
stream: stream & RBIT
Expand Down Expand Up @@ -359,7 +359,7 @@ def generate(frame)
# Padding: Padding octets that contain no application semantic value.
# Padding octets MUST be set to zero when sending and ignored when
# receiving.
append_str(bytes, ("\0" * padlen))
append_str(bytes, "\0" * padlen)
end

frame[:length] = length
Expand Down
29 changes: 16 additions & 13 deletions lib/http/2/header/encoding_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def process(cmd)
emit = [name, value]

# add to table
if type == :incremental && size_check(name.bytesize + value.bytesize + 32)
if type == :incremental && size_check?(name.bytesize + value.bytesize + 32)
@table.unshift(emit)
@current_table_size += name.bytesize + value.bytesize + 32
@_table_updated = true
Expand Down Expand Up @@ -302,7 +302,7 @@ def addcmd(field, value)
# When the size is reduced, some headers might be evicted.
def table_size=(size)
@limit = size
size_check(0)
resize_table(0)
end

def listen_on_table
Expand All @@ -313,22 +313,25 @@ def listen_on_table

private

def resize_table(cmdsize)
return if @table.empty?

while @current_table_size + cmdsize > @limit

name, value = @table.pop
@current_table_size -= name.bytesize + value.bytesize + 32
break if @table.empty?

end
end

# To keep the dynamic table size lower than or equal to @limit,
# remove one or more entries at the end of the dynamic table.
#
# @param cmdsize [Integer]
# @return [Boolean] whether +cmd+ fits in the dynamic table.
def size_check(cmdsize)
unless @table.empty?
while @current_table_size + cmdsize > @limit

name, value = @table.pop
@current_table_size -= name.bytesize + value.bytesize + 32
break if @table.empty?

end
end

def size_check?(cmdsize)
resize_table(cmdsize)
cmdsize <= @limit
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/http/2/header/huffman.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module Huffman
def encode(str, buffer = "".b)
bitstring = String.new("", encoding: Encoding::BINARY, capacity: (str.bytesize * 30) + ((8 - str.size) % 8))
str.each_byte { |chr| append_str(bitstring, ENCODE_TABLE[chr]) }
append_str(bitstring, ("1" * ((8 - bitstring.size) % 8)))
append_str(bitstring, "1" * ((8 - bitstring.size) % 8))
pack([bitstring], "B*", buffer: buffer)
end

Expand Down
4 changes: 3 additions & 1 deletion sig/header/encoding_context.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ module HTTP2

def add_to_table: (string name, string value) -> void

def size_check: (Integer cmdsize) -> bool
def resize_table: (Integer cmdsize) -> void

def size_check?: (Integer cmdsize) -> bool
end
end
end
1 change: 1 addition & 0 deletions spec/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

RSpec.describe HTTP2::Connection do
include FrameHelpers

let(:conn) { Client.new }
let(:f) { Framer.new }

Expand Down
1 change: 1 addition & 0 deletions spec/emitter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
RSpec.describe HTTP2::Emitter do
class Worker
include Emitter

def initialize
@listeners = Hash.new { |hash, key| hash[key] = [] }
end
Expand Down
6 changes: 4 additions & 2 deletions spec/shared_examples/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,13 @@
expect { conn << f.generate(ping_frame) }.not_to raise_error(ProtocolError)
end

it "should respond with protocol error when receiving goaway" do
it "should ignore additional goaway" do
expect { conn << f.generate(settings_frame) }.not_to raise_error(ProtocolError)

conn.goaway
expect(conn).to be_closed

expect { conn << f.generate(goaway_frame) }.to raise_error(ProtocolError)
expect { conn << f.generate(goaway_frame) }.not_to raise_error(ProtocolError)
end

it "should raise error on frame for invalid stream ID" do
Expand Down
1 change: 1 addition & 0 deletions spec/stream_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

RSpec.describe HTTP2::Stream do
include FrameHelpers

let(:f) { Framer.new }
let(:client) { Client.new }
let(:stream) { client.new_stream }
Expand Down
6 changes: 3 additions & 3 deletions tasks/generate_huffman_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def add(code, len, chr)
if len.zero?
@emit = chr
else
bit = code.nobits?((1 << (len - 1))) ? 0 : 1
bit = code.nobits?(1 << (len - 1)) ? 0 : 1
node = @next[bit] ||= Node.new(@depth + 1)
node.add(code, len - 1, chr)
end
Expand Down Expand Up @@ -70,7 +70,7 @@ def self.generate_machine
n = node
emit = "".b
(BITS_AT_ONCE - 1).downto(0) do |i|
bit = input.nobits?((1 << i)) ? 0 : 1
bit = input.nobits?(1 << i) ? 0 : 1
n = n.next[bit]
next unless n.emit

Expand Down Expand Up @@ -123,7 +123,7 @@ class Huffman
id.times do |i|
n = id_state[i]
f.print " ["
string = Array.new((1 << 4)) do |t|
string = Array.new(1 << 4) do |t|
transition = n.transitions.fetch(t)
emit = transition.emit
unless emit == EOS
Expand Down