| 1 |
package Protocol::HTTP2::Frame::Rst_stream; |
| 2 |
use strict; |
| 3 |
use warnings; |
| 4 |
use Protocol::HTTP2::Constants qw(const_name :flags :errors); |
| 5 |
use Protocol::HTTP2::Trace qw(tracer); |
| 6 |
|
| 7 |
sub decode { |
| 8 |
my ( $con, $buf_ref, $buf_offset, $length ) = @_; |
| 9 |
my $frame_ref = $con->decode_context->{frame}; |
| 10 |
|
| 11 |
# RST_STREAM associated with stream |
| 12 |
if ( $frame_ref->{stream} == 0 ) { |
| 13 |
tracer->error("Received reset stream with stream id 0"); |
| 14 |
$con->error(PROTOCOL_ERROR); |
| 15 |
return undef; |
| 16 |
} |
| 17 |
|
| 18 |
if ( $length != 4 ) { |
| 19 |
tracer->error("Received reset stream with invalid length $length"); |
| 20 |
$con->error(FRAME_SIZE_ERROR); |
| 21 |
return undef; |
| 22 |
} |
| 23 |
|
| 24 |
my $code = unpack( 'N', substr( $$buf_ref, $buf_offset, 4 ) ); |
| 25 |
|
| 26 |
tracer->debug( "Receive reset stream with error code " |
| 27 |
. const_name( "errors", $code ) |
| 28 |
. "\n" ); |
| 29 |
$con->stream_reset( $frame_ref->{stream}, $code ); |
| 30 |
|
| 31 |
return $length; |
| 32 |
} |
| 33 |
|
| 34 |
sub encode { |
| 35 |
my ( $con, $flags_ref, $stream, $data ) = @_; |
| 36 |
$con->stream_reset( $stream, $data ); |
| 37 |
return pack 'N', $data; |
| 38 |
} |
| 39 |
|
| 40 |
1; |