-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove HTTP/2 Push Promise support since Plug is deprecating it #33
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9a85873
Remove push promise support since Plug is deprecating it
mtrudel 66e0792
Remove support for Push Promise frame
mtrudel 0c7922f
Remove test client push promise support
mtrudel 04adb65
Remove unused stream ID function
mtrudel 62789e3
Group two no-op setting parsing clauses
mtrudel File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,100 +1,11 @@ | ||
defmodule Bandit.HTTP2.Frame.PushPromise do | ||
@moduledoc false | ||
|
||
import Bandit.HTTP2.Frame.Flags | ||
|
||
alias Bandit.HTTP2.{Connection, Errors, Frame, Stream} | ||
|
||
defstruct stream_id: nil, | ||
end_headers: false, | ||
promised_stream_id: nil, | ||
fragment: nil | ||
|
||
@typedoc "An HTTP/2 PUSH_PROMISE frame" | ||
@type t :: %__MODULE__{ | ||
stream_id: Stream.stream_id(), | ||
end_headers: boolean(), | ||
promised_stream_id: Stream.stream_id(), | ||
fragment: iodata() | ||
} | ||
|
||
@end_headers_bit 2 | ||
@padding_bit 3 | ||
|
||
@spec deserialize(Frame.flags(), Stream.stream_id(), iodata()) :: | ||
{:ok, t()} | {:error, Connection.error()} | ||
def deserialize(_flags, 0, _payload) do | ||
{:error, | ||
{:connection, Errors.protocol_error(), | ||
"PUSH_PROMISE frame with zero stream_id (RFC7540§6.6)"}} | ||
end | ||
|
||
def deserialize( | ||
flags, | ||
stream_id, | ||
<<padding_length::8, 0::1, promised_stream_id::31, rest::binary>> | ||
) | ||
when set?(flags, @padding_bit) and byte_size(rest) >= padding_length do | ||
{:ok, | ||
%__MODULE__{ | ||
stream_id: stream_id, | ||
end_headers: set?(flags, @end_headers_bit), | ||
promised_stream_id: promised_stream_id, | ||
fragment: binary_part(rest, 0, byte_size(rest) - padding_length) | ||
}} | ||
end | ||
|
||
def deserialize(flags, stream_id, <<0::1, promised_stream_id::31, fragment::binary>>) | ||
when clear?(flags, @padding_bit) do | ||
{:ok, | ||
%__MODULE__{ | ||
stream_id: stream_id, | ||
end_headers: set?(flags, @end_headers_bit), | ||
promised_stream_id: promised_stream_id, | ||
fragment: fragment | ||
}} | ||
end | ||
|
||
def deserialize( | ||
flags, | ||
_stream_id, | ||
<<_padding_length::8, _reserved::1, _promised_stream_id::31, _rest::binary>> | ||
) | ||
when set?(flags, @padding_bit) do | ||
{:error, | ||
{:connection, Errors.protocol_error(), | ||
"PUSH_PROMISE frame with invalid padding length (RFC7540§6.6)"}} | ||
end | ||
|
||
defimpl Frame.Serializable do | ||
alias Bandit.HTTP2.Frame.{Continuation, PushPromise} | ||
|
||
@end_headers_bit 2 | ||
|
||
def serialize(%PushPromise{} = frame, max_frame_size) do | ||
fragment_length = IO.iodata_length(frame.fragment) | ||
max_fragment_size = max_frame_size - 4 | ||
|
||
if fragment_length <= max_fragment_size do | ||
[ | ||
{0x5, set([@end_headers_bit]), frame.stream_id, | ||
[<<frame.promised_stream_id::32>>, frame.fragment]} | ||
] | ||
else | ||
<<this_frame::binary-size(max_fragment_size), rest::binary>> = | ||
IO.iodata_to_binary(frame.fragment) | ||
|
||
[ | ||
{0x5, 0x00, frame.stream_id, <<frame.promised_stream_id::32, this_frame::binary>>} | ||
| Frame.Serializable.serialize( | ||
%Continuation{ | ||
stream_id: frame.stream_id, | ||
fragment: rest | ||
}, | ||
max_frame_size | ||
) | ||
] | ||
end | ||
end | ||
{:error, Connection.error()} | ||
def deserialize(_flags, _stream, _payload) do | ||
{:error, {:connection, Errors.protocol_error(), "PUSH_PROMISE frame received (RFC7540§8.2)"}} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove these cases all together (and ignore invalid
enable_push
values)?h2spec
seems fine with it.Otherwise group the valid cases to
{:ok, {0x02, val}}, {:ok, acc} when val in [0x00, 0x01] ->
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to keep the handling, even if h2spec doesn't complain. No sense in walking back strict conformance.
Updated to use a when clause, as suggested
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe use
{:ok, {0x02, value}}, {:ok, _acc} when value not in [0x00, 0x01]
on the error case and drop the noop case?