http-2
http-2 copied to clipboard
Connection upgrade fails when request body is not empty
Hi and thanks for this wonderful gem! When upgrading an HTTP/1.1 connection (e.g. using curl --http2
), if the HTTP/1.1 request body passed to HTTP2::Server#upgrade
is not empty, the upgrade will fail with the following traceback:
Traceback (most recent call last):
12: from /home/sharon/repo/tipi/lib/tipi.rb:39:in `block (2 levels) in accept_loop'
<snip>
3: from /home/sharon/.gem/gems/http-2-0.11.0/lib/http/2/server.rb:102:in `upgrade'
2: from /home/sharon/.gem/gems/http-2-0.11.0/lib/http/2/stream.rb:102:in `receive'
1: from /home/sharon/.gem/gems/http-2-0.11.0/lib/http/2/stream.rb:321:in `transition'
/home/sharon/.gem/gems/http-2-0.11.0/lib/http/2/stream.rb:604:in `end_stream?': undefined method `include?' for nil:NilClass (NoMethodError)
The fix is trivial:
class HTTP2::Stream
def end_stream?(frame)
case frame[:type]
when :data, :headers, :continuation
frame[:flags]&.include?(:end_stream)
else false
end
end
end
The fix is just to add the safe navigation operator when checking for frame[:flags]
, since it's its not set when the body is not empty.