Langertha-Knarr

 view release on metacpan or  search on metacpan

lib/Langertha/Knarr.pm  view on Meta::CPAN

    scalar $resp->header('Content-Type') // 'application/json',
    $resp->content // '',
    $self->_raw_passthrough_response_headers($resp) );
}

# Upstream response headers that stay behind: connection-level ones, the
# framing Knarr sets for what it sends itself, Content-Type, which the
# callers set, and the note Net::Async::HTTP leaves on a body it decoded.
my %RESPONSE_HEADER_SKIP = map { $_ => 1 } qw(
  connection keep-alive proxy-connection te trailer upgrade
  transfer-encoding content-length content-type x-original-content-encoding );

# The upstream's response headers that go back to the client, as [ name,
# value ] pairs: every line, a repeated header (Set-Cookie) repeated in its
# order (k56). Content-Encoding goes along only while the bytes still carry
# it: Net::Async::HTTP decodes every encoding it knows (gzip, deflate)
# before Knarr sees a byte, buffered or streamed, and passes any other as
# it came (k59). The decision is its own: the whole header value, repeated
# lines joined, is what it looks up -- in on_header it has not removed the
# header yet, on a finished response it has.
sub _raw_passthrough_response_headers {

t/80_raw_passthrough_psgi_parity.t  view on Meta::CPAN

  is( scalar $n->{resp}->header('Content-Type'), $ctype, "$label: native keeps the upstream content type" );
  is( $n->{resp}->content, $expected, "$label: native returns the upstream bytes 1:1" );
  is( $p->{resp}->content, $expected, "$label: PSGI returns the upstream bytes 1:1" );

  is( scalar @{ $n->{upstream} }, 1, "$label: native hits the upstream once" );
  is( scalar @{ $p->{upstream} }, 1, "$label: PSGI hits the upstream once" );
  my ($nu, $pu) = ( $n->{upstream}[0], $p->{upstream}[0] );
  is( $pu->{path}, $nu->{path}, "$label: same upstream path" );
  is( $nu->{body}, $content, "$label: native forwards the client body 1:1" );
  is( $pu->{body}, $content, "$label: PSGI forwards the client body 1:1" );
  for my $hname ( 'x-api-key', 'anthropic-version', 'x-custom-trace', 'content-type' ) {
    is( $pu->{headers}{$hname}, $nu->{headers}{$hname}, "$label: header $hname forwarded alike" );
    ok( defined $nu->{headers}{$hname}, "$label: header $hname reaches the upstream" );
  }
}

done_testing;



( run in 1.785 second using v1.01-cache-2.11-cpan-99fa8243a42 )