| 1 | package HTTP::Proxy::HeaderFilter::standard; | ||||||||||||||||||||||||||||
| 2 | 67 | $HTTP::Proxy::HeaderFilter::standard::VERSION = '0.304'; | |||||||||||||||||||||||||||
| 3 | 67 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 67 | ▶ | use HTTP::Proxy; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 67 | ▶ | use HTTP::Headers::Util qw( split_header_words ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 67 | ▶ | use HTTP::Proxy::HeaderFilter; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 67 | ▶ | use vars qw( @ISA ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 67 | @ISA = qw( HTTP::Proxy::HeaderFilter ); | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | # known hop-by-hop headers | ||||||||||||||||||||||||||||
| 11 | 67 | my @hopbyhop = | |||||||||||||||||||||||||||
| 12 | qw( Connection Keep-Alive Proxy-Authenticate Proxy-Authorization | ||||||||||||||||||||||||||||
| 13 | TE Trailers Transfer-Encoding Upgrade Proxy-Connection Public ); | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | # standard proxy header filter (RFC 2616) | ||||||||||||||||||||||||||||
| 16 | 62 | ▶ | sub filter { | ||||||||||||||||||||||||||
|
Subroutine
filter: called CC=15 SCAR=30.3
Pod
documented
| |||||||||||||||||||||||||||||
| 17 | 62 | my ( $self, $headers, $message ) = @_; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # the Via: header | ||||||||||||||||||||||||||||
| 20 | 62 | ▶ | my $via = $message->protocol() || ''; | ||||||||||||||||||||||||||
|
Condition100%2/2
$message->protocol || ''
MC/DC100%1/1
$message->protocol || ''
$message->protocol
Truth table100%2/2
A
A= $message->protocol
| |||||||||||||||||||||||||||||
| 21 | 62 | ▶ | if ( $self->proxy->via and $via =~ s!HTTP/!! ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->proxy->via and $via =~ s[HTTP/][]
MC/DC100%2/2
$self->proxy->via and $via =~ s[HTTP/][]
$self->proxy->via
$via =~ s[HTTP/][]
Truth table100%3/3
A and B
A= $self->proxy->viaB= $via =~ s[HTTP/][]
| |||||||||||||||||||||||||||||
| 22 | 53 | $via .= " " . $self->proxy->via; | |||||||||||||||||||||||||||
| 23 | 53 | ▶ | $headers->header( | ||||||||||||||||||||||||||
|
Condition66%2/3
$message->headers->header('Via') || ()
MC/DC0%0/2
$message->headers->header('Via') || ()
$message->headers->header('Via')
()
Truth table66%2/3
A || B
A= $message->headers->header('Via')B= ()
| |||||||||||||||||||||||||||||
| 24 | Via => join ', ', | ||||||||||||||||||||||||||||
| 25 | $message->headers->header('Via') || (), $via | ||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | # the X-Forwarded-For header | ||||||||||||||||||||||||||||
| 30 | $headers->push_header( | ||||||||||||||||||||||||||||
| 31 | 62 | ▶ | X_Forwarded_For => $self->proxy->client_socket->peerhost ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$message->isa("HTTP::Request") and $self->proxy->x_forwarded_for
MC/DC100%2/2
$message->isa("HTTP::Request") and $self->proxy->x_forwarded_for
$message->isa("HTTP::Request")
$self->proxy->x_forwarded_for
Truth table100%3/3
A and B
A= $message->isa("HTTP::Request")B= $self->proxy->x_forwarded_for
| |||||||||||||||||||||||||||||
| 32 | if $message->isa( 'HTTP::Request' ) && $self->proxy->x_forwarded_for; | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | # make a list of hop-by-hop headers | ||||||||||||||||||||||||||||
| 35 | 62 | my %h2h = map { (lc) => 1 } @hopbyhop; | |||||||||||||||||||||||||||
| 36 | 62 | my $hop = HTTP::Headers->new(); | |||||||||||||||||||||||||||
| 37 | 62 | my $client = HTTP::Headers->new(); | |||||||||||||||||||||||||||
| 38 | $h2h{ lc $_->[0] } = 1 | ||||||||||||||||||||||||||||
| 39 | 62 | for map { split_header_words($_) } $headers->header('Connection'); | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | # hop-by-hop headers are set aside | ||||||||||||||||||||||||||||
| 42 | # as well as LWP::UserAgent Client-* headers | ||||||||||||||||||||||||||||
| 43 | $headers->scan( | ||||||||||||||||||||||||||||
| 44 | 399 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 45 | 399 | my ( $k, $v ) = @_; | |||||||||||||||||||||||||||
| 46 | 399 | ▶ | if ( $h2h{lc $k} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 72 | $hop->push_header( $k => $v ); | |||||||||||||||||||||||||||
| 48 | 72 | $headers->remove_header($k); | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | 399 | ▶ | if( $k =~ /^Client-/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 52 | $client->push_header( $k => $v ); | |||||||||||||||||||||||||||
| 52 | 52 | $headers->remove_header($k); | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | 62 | ); | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | # set the hop-by-hop and client headers in the proxy | ||||||||||||||||||||||||||||
| 58 | # only the end-to-end headers are left in the message | ||||||||||||||||||||||||||||
| 59 | 62 | $self->proxy->hop_headers($hop); | |||||||||||||||||||||||||||
| 60 | 62 | $self->proxy->client_headers($client); | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | # handle Max-Forwards | ||||||||||||||||||||||||||||
| 63 | 62 | ▶ | if ( $message->isa('HTTP::Request') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$message->isa("HTTP::Request") and defined $headers->header("Max-Forwards")
MC/DC0%0/2
$message->isa("HTTP::Request") and defined $headers->header("Max-Forwards")
$message->isa("HTTP::Request")
defined $headers->header("Max-Forwards")
Truth table66%2/3
A and B
A= $message->isa("HTTP::Request")B= defined $headers->header("Max-Forwards")
| |||||||||||||||||||||||||||||
| 64 | and defined $headers->header('Max-Forwards') ) { | ||||||||||||||||||||||||||||
| 65 | 0 | my ( $max, $method ) = | |||||||||||||||||||||||||||
| 66 | ( $headers->header('Max-Forwards'), $message->method ); | ||||||||||||||||||||||||||||
| 67 | 0 | ▶ | if ( $max == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 68 | # answer directly TRACE ou OPTIONS | ||||||||||||||||||||||||||||
| 69 | 0 | ▶ | if ( $method eq 'TRACE' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 70 | 0 | my $response = | |||||||||||||||||||||||||||
| 71 | HTTP::Response->new( 200, 'OK', | ||||||||||||||||||||||||||||
| 72 | HTTP::Headers->new( Content_Type => 'message/http' | ||||||||||||||||||||||||||||
| 73 | , Content_Length => 0), | ||||||||||||||||||||||||||||
| 74 | $message->as_string ); | ||||||||||||||||||||||||||||
| 75 | 0 | $self->proxy->response($response); | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | elsif ( $method eq 'OPTIONS' ) { | ||||||||||||||||||||||||||||
| 78 | 0 | my $response = HTTP::Response->new(200); | |||||||||||||||||||||||||||
| 79 | 0 | $response->header( Allow => join ', ', @HTTP::Proxy::METHODS ); | |||||||||||||||||||||||||||
| 80 | 0 | $self->proxy->response($response); | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | # The Max-Forwards header field MAY be ignored for all | ||||||||||||||||||||||||||||
| 84 | # other methods defined by this specification (RFC 2616) | ||||||||||||||||||||||||||||
| 85 | elsif ( $method =~ /^(?:TRACE|OPTIONS)/ ) { | ||||||||||||||||||||||||||||
| 86 | 0 | $headers->header( 'Max-Forwards' => --$max ); | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | # no encoding accepted (gzip, compress, deflate) | ||||||||||||||||||||||||||||
| 91 | # if we plan to do anything with the response body | ||||||||||||||||||||||||||||
| 92 | $headers->remove_header( 'Accept-Encoding' ) | ||||||||||||||||||||||||||||
| 93 | 62 | ▶ | if @{ $self->proxy->{body}{response}{filters} }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 67 | 1; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | __END__ | ||||||||||||||||||||||||||||