| 1 |
package Protocol::HTTP2::Frame::Goaway; |
| 2 |
use strict; |
| 3 |
use warnings; |
| 4 |
use Protocol::HTTP2::Constants qw(const_name :flags :errors); |
| 5 |
use Protocol::HTTP2::Trace qw(tracer bin2hex); |
| 6 |
|
| 7 |
sub decode { |
| 8 |
my ( $con, $buf_ref, $buf_offset, $length ) = @_; |
| 9 |
my $frame_ref = $con->decode_context->{frame}; |
| 10 |
|
| 11 |
if ( $frame_ref->{stream} != 0 ) { |
| 12 |
$con->error(PROTOCOL_ERROR); |
| 13 |
return undef; |
| 14 |
} |
| 15 |
|
| 16 |
my ( $last_stream_id, $error_code ) = |
| 17 |
unpack( 'N2', substr( $$buf_ref, $buf_offset, 8 ) ); |
| 18 |
|
| 19 |
$last_stream_id &= 0x7FFF_FFFF; |
| 20 |
|
| 21 |
tracer->debug( "GOAWAY with error code " |
| 22 |
. const_name( 'errors', $error_code ) |
| 23 |
. " last stream is $last_stream_id\n" ); |
| 24 |
|
| 25 |
tracer->debug( "additional debug data: " |
| 26 |
. bin2hex( substr( $$buf_ref, $buf_offset + 8 ) ) |
| 27 |
. "\n" ) |
| 28 |
if $length - 8 > 0; |
| 29 |
|
| 30 |
$con->goaway(1); |
| 31 |
|
| 32 |
return $length; |
| 33 |
} |
| 34 |
|
| 35 |
sub encode { |
| 36 |
my ( $con, $flags_ref, $stream, $data ) = @_; |
| 37 |
|
| 38 |
$con->goaway(1); |
| 39 |
|
| 40 |
my $payload = pack( 'N2', @$data ); |
| 41 |
tracer->debug( "\tGOAWAY: last stream = $data->[0], error = " |
| 42 |
. const_name( "errors", $data->[1] ) |
| 43 |
. "\n" ); |
| 44 |
$payload .= $data->[2] if @$data > 2; |
| 45 |
return $payload; |
| 46 |
} |
| 47 |
|
| 48 |
1; |