| 1 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 2 | ## Asynchronous HTTP Request and Promise - ~/lib/HTTP/Promise/Headers/Forwarded.pm | ||||||||||||||||||||||||||||
| 3 | ## Version v0.1.0 | ||||||||||||||||||||||||||||
| 4 | ## Copyright(c) 2022 DEGUEST Pte. Ltd. | ||||||||||||||||||||||||||||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||||||||||||||||||||||||||||
| 6 | ## Created 2022/05/08 | ||||||||||||||||||||||||||||
| 7 | ## Modified 2022/05/08 | ||||||||||||||||||||||||||||
| 8 | ## All rights reserved. | ||||||||||||||||||||||||||||
| 9 | ## | ||||||||||||||||||||||||||||
| 10 | ## | ||||||||||||||||||||||||||||
| 11 | ## This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 12 | ## under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 13 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 14 | package HTTP::Promise::Headers::Forwarded; | ||||||||||||||||||||||||||||
| 15 | BEGIN | ||||||||||||||||||||||||||||
| 16 | { | ||||||||||||||||||||||||||||
| 17 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 3 | ▶ | warnings::register_categories( 'HTTP::Promise' ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 3 | ▶ | use parent qw( HTTP::Promise::Headers::Generic ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 3 | our $VERSION = 'v0.1.0'; | |||||||||||||||||||||||||||
| 22 | }; | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | sub init | ||||||||||||||||||||||||||||
| 28 | { | ||||||||||||||||||||||||||||
| 29 | 4 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=7 SCAR=19.7
Pod
documented
| |||||||||||||||||||||||||||||
| 30 | 4 | $self->{params} = []; | |||||||||||||||||||||||||||
| 31 | 4 | $self->{properties} = {}; | |||||||||||||||||||||||||||
| 32 | # Works like HTTP::Promise::Headers::CacheControl | ||||||||||||||||||||||||||||
| 33 | 4 | ▶ | @_ = () if( @_ == 1 && $self->_is_a( $_[0] => 'Module::Generic::Null' ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ == 1 and $self->_is_a($_[0], "Module::Generic::Null")
MC/DC0%0/2
@_ == 1 and $self->_is_a($_[0], "Module::Generic::Null")
@_ == 1
$self->_is_a($_[0], "Module::Generic::Null")
Truth table66%2/3
A and B
A= @_ == 1B= $self->_is_a($_[0], "Module::Generic::Null")
| |||||||||||||||||||||||||||||
| 34 | 4 | ▶ | if( @_ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | { | ||||||||||||||||||||||||||||
| 36 | 3 | my $this = shift( @_ ); | |||||||||||||||||||||||||||
| 37 | 3 | ▶ | my $ref = $self->_is_array( $this ) ? $this : [split( /(?<!\\)\;[[:blank:]\h]*/, "$this" )]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 3 | my $params = $self->params; | |||||||||||||||||||||||||||
| 39 | 3 | my $props = $self->properties; | |||||||||||||||||||||||||||
| 40 | 3 | foreach my $pair ( @$ref ) | |||||||||||||||||||||||||||
| 41 | { | ||||||||||||||||||||||||||||
| 42 | 9 | my( $prop, $val ) = split( /=/, $pair, 2 ); | |||||||||||||||||||||||||||
| 43 | 9 | $props->{ $prop } = $val; | |||||||||||||||||||||||||||
| 44 | 9 | $params->push( $prop ); | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | 4 | $self->{_init_strict_use_sub} = 1; | |||||||||||||||||||||||||||
| 48 | 4 | ▶ | $self->SUPER::init( @_ ) || return( $self->pass_error ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 4 | $self->_field_name( 'Forwarded' ); | |||||||||||||||||||||||||||
| 50 | 4 | return( $self ); | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 5 | ▶ | sub as_string { return( shift->_set_get_properties_as_string( sep => ';' ) ); } | ||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 5 | ▶ | sub by { return( shift->_set_get_property_value( 'by', @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
by: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 5 | ▶ | sub for { return( shift->_set_get_property_value( 'for', @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
for: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub host { return( shift->_set_get_property_value( 'host', @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
host: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 23 | ▶ | sub params { return( shift->_set_get_array_as_object( 'params', @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
params: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 23 | ▶ | sub properties { return( shift->_set_get_hash_as_mix_object( 'properties', @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
properties: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 5 | ▶ | sub proto { return( shift->_set_get_property_value( 'proto', @_ ) ); } | ||||||||||||||||||||||||||
|
Subroutine
proto: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 3 | 1; | |||||||||||||||||||||||||||
| 68 | # NOTE: POD | ||||||||||||||||||||||||||||
| 69 | __END__ | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | =encoding utf-8 | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =head1 NAME | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | HTTP::Promise::Headers::Forwarded - Forwarded Header Field | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | use HTTP::Promise::Headers::Forwarded; | ||||||||||||||||||||||||||||
| 80 | my $fwd = HTTP::Promise::Headers::Forwarded->new || | ||||||||||||||||||||||||||||
| 81 | die( HTTP::Promise::Headers::Forwarded->error, "\n" ); | ||||||||||||||||||||||||||||
| 82 | $h->by( 'secret' ); | ||||||||||||||||||||||||||||
| 83 | $h->for( '192.0.2.43' ); | ||||||||||||||||||||||||||||
| 84 | $h->host( 'example.com' ); | ||||||||||||||||||||||||||||
| 85 | $h->proto( 'https' ); | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =head1 VERSION | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | v0.1.0 | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | The following is an extract from Mozilla documentation. | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | The C<Forwarded> request header contains information that may be added by reverse proxy servers (load balancers, CDNs, and so on) that would otherwise be altered or lost when proxy servers are involved in the path of the request. | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | For example: | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | Forwarded: for=192.0.2.60;proto=http;by=203.0.113.43 | ||||||||||||||||||||||||||||
| 100 | # Values from multiple proxy servers can be appended using a comma | ||||||||||||||||||||||||||||
| 101 | Forwarded: for=192.0.2.43, for=198.51.100.17 | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | =head1 METHODS | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | =head2 as_string | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | Returns a string representation of the C<Forwarded> object. | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | =head2 by | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | This is optional. | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | The interface where the request came in to the proxy server. The identifier can be: | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | =head2 for | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | This is optional. | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | The client that initiated the request and subsequent proxies in a chain of proxies. The identifier has the same possible values as the by directive. | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | =head2 host | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | This is optional. | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | The Host request header field as received by the proxy. | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | =head2 params | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | Sets or gets the L<array object|Module::Generic::Array> containing all the parameters in their proper order. | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | =head2 properties | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | Sets or gets an hash or hash reference ot property-value pairs. | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | =head2 proto | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | This is optional. | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | Indicates which protocol was used to make the request (typically "http" or "https"). | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | =head1 THREAD-SAFETY | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | This module is thread-safe for all operations, as it operates on per-object state and uses thread-safe external libraries. | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | Jacques Deguest E<lt>F<jack@deguest.jp>E<gt> | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | See also L<rfc7239, section 4|https://tools.ietf.org/html/rfc7239#section-4> and L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Forwarded> | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | L<HTTP::Promise>, L<HTTP::Promise::Request>, L<HTTP::Promise::Response>, L<HTTP::Promise::Message>, L<HTTP::Promise::Entity>, L<HTTP::Promise::Headers>, L<HTTP::Promise::Body>, L<HTTP::Promise::Body::Form>, L<HTTP::Promise::Body::Form::Data>, L<HTTP::Promise::Body::Form::Field>, L<HTTP::Promise::Status>, L<HTTP::Promise::MIME>, L<HTTP::Promise::Parser>, L<HTTP::Promise::IO>, L<HTTP::Promise::Stream>, L<HTTP::Promise::Exception> | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | Copyright(c) 2022 DEGUEST Pte. Ltd. | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | All rights reserved. | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | =cut | ||||||||||||||||||||||||||||