| 1 | package HTTP::Request::FromWget 0.57; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use 5.020; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use HTTP::Request; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use HTTP::Request::Common; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use URI; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Getopt::Long; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use File::Spec::Unix; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use HTTP::Request::CurlParameters; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use HTTP::Request::Generator 'generate_requests'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use PerlX::Maybe; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use MIME::Base64 'encode_base64'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use feature 'signatures'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | no warnings 'experimental::signatures'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | HTTP::Request::FromWget - create a HTTP::Request from a wget command line | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | my $req = HTTP::Request::FromWget->new( | ||||||||||||||||||||||||||||||||||||||||||
| 23 | # Note - wget itself may not appear | ||||||||||||||||||||||||||||||||||||||||||
| 24 | argv => ['https://example.com'], | ||||||||||||||||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | my $req = HTTP::Request::FromWget->new( | ||||||||||||||||||||||||||||||||||||||||||
| 28 | command => 'https://example.com', | ||||||||||||||||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | my $req = HTTP::Request::FromWget->new( | ||||||||||||||||||||||||||||||||||||||||||
| 32 | command_wget => 'wget -A mywget/1.0 https://example.com', | ||||||||||||||||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | my @requests = HTTP::Request::FromWget->new( | ||||||||||||||||||||||||||||||||||||||||||
| 36 | command_wget => 'wget -A mywget/1.0 https://example.com https://www.example.com', | ||||||||||||||||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 38 | # Send the requests | ||||||||||||||||||||||||||||||||||||||||||
| 39 | for my $r (@requests) { | ||||||||||||||||||||||||||||||||||||||||||
| 40 | $ua->request( $r->as_request ) | ||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | =head1 RATIONALE | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | C<wget> command lines are found everywhere in documentation. The Firefox | ||||||||||||||||||||||||||||||||||||||||||
| 46 | developer tools can also copy network requests as C<wget> command lines from | ||||||||||||||||||||||||||||||||||||||||||
| 47 | the network panel. This module enables converting these to Perl code. | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | =head2 C<< ->new >> | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | my $req = HTTP::Request::FromWget->new( | ||||||||||||||||||||||||||||||||||||||||||
| 54 | # Note - wget itself may not appear | ||||||||||||||||||||||||||||||||||||||||||
| 55 | argv => ['--user-agent', 'myscript/1.0', 'https://example.com'], | ||||||||||||||||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | my $req = HTTP::Request::FromWget->new( | ||||||||||||||||||||||||||||||||||||||||||
| 59 | # Note - wget itself may not appear | ||||||||||||||||||||||||||||||||||||||||||
| 60 | command => '--user-agent myscript/1.0 https://example.com', | ||||||||||||||||||||||||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | The constructor returns one or more L<HTTP::Request::CurlParameters> objects | ||||||||||||||||||||||||||||||||||||||||||
| 64 | that encapsulate the parameters. If the command generates multiple requests, | ||||||||||||||||||||||||||||||||||||||||||
| 65 | they will be returned in list context. In scalar context, only the first request | ||||||||||||||||||||||||||||||||||||||||||
| 66 | will be returned. | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | my $req = HTTP::Request::FromWget->new( | ||||||||||||||||||||||||||||||||||||||||||
| 69 | command => '--post-file /etc/passwd https://example.com', | ||||||||||||||||||||||||||||||||||||||||||
| 70 | read_files => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 71 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | =head3 Options | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | =item B<argv> | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | An arrayref of commands as could be given in C< @ARGV >. | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | =item B<command> | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | A scalar in a command line, excluding the C<wget> command | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | =item B<command_wget> | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | A scalar in a command line, including the C<wget> command | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | =item B<read_files> | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | Do read in the content of files specified with (for example) | ||||||||||||||||||||||||||||||||||||||||||
| 92 | C<< --data=@/etc/passwd >>. The default is to not read the contents of files | ||||||||||||||||||||||||||||||||||||||||||
| 93 | specified this way. | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | =head1 GLOBAL VARIABLES | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | =head2 C<< %default_headers >> | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | Contains the default headers added to every request | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 3 | our %default_headers = ( | |||||||||||||||||||||||||||||||||||||||||
| 106 | 'Accept' => '*/*', | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 'Accept-Encoding' => 'identity', | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 'User-Agent' => 'Wget/1.21', | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 'Connection' => 'Keep-Alive', | ||||||||||||||||||||||||||||||||||||||||||
| 110 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | =head2 C<< @option_spec >> | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | Contains the L<Getopt::Long> specification of the recognized command line | ||||||||||||||||||||||||||||||||||||||||||
| 115 | parameters. | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | The following C<wget> options are recognized but largely ignored: | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | =item B<verbose> | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | =item B<quiet> | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | =item B<auth-no-challenge> | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | =item B<output-document> | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | =item B<debug> | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | If you want to keep session cookies between subsequent requests, you need to | ||||||||||||||||||||||||||||||||||||||||||
| 132 | provide a cookie jar in your user agent. | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 3 | our @option_spec = ( | |||||||||||||||||||||||||||||||||||||||||
| 139 | 'auth-no-challenge', # ignored | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 'bind-address=s', | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 'body-data=s', | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 'body-file=s', | ||||||||||||||||||||||||||||||||||||||||||
| 143 | 'buffer!', | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 'cache!', | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 'ca-directory=s', | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 'check-certificate!', | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 'certificate=s', | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 'compression=s', | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 'content-disposition=s', | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 'cookie|b=s@', | ||||||||||||||||||||||||||||||||||||||||||
| 151 | 'cookies!', # ignored | ||||||||||||||||||||||||||||||||||||||||||
| 152 | 'debug', # ignored | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 'header|H=s@', | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 'http-keep-alive!', | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 'http-password=s', | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 'http-user=s', | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 'load-cookies|c=s', | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 'method=s', | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 'no-verbose|nv', # ignored | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 'output-document|O=s', # ignored | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 'post-data=s', | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 'post-file=s', | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 'progress!', # ignored | ||||||||||||||||||||||||||||||||||||||||||
| 164 | 'quiet', # ignored | ||||||||||||||||||||||||||||||||||||||||||
| 165 | 'referer=s', | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 'timeout|T=i', | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 'user-agent|U=s', | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 'verbose|v', # ignored | ||||||||||||||||||||||||||||||||||||||||||
| 169 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | sub new( $class, %options ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | my $cmd = $options{ argv }; | |||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | if( $options{ command }) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | require Text::ParseWords; | |||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | $cmd = [ Text::ParseWords::shellwords($options{ command }) ]; | |||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | } elsif( $options{ command_wget }) { | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | require Text::ParseWords; | |||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | $cmd = [ Text::ParseWords::shellwords($options{ command_wget }) ]; | |||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | # remove the implicit wget command: | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | shift @$cmd; | |||||||||||||||||||||||||||||||||||||||||
| 184 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | my $p = Getopt::Long::Parser->new( | |||||||||||||||||||||||||||||||||||||||||
| 187 | config => [ 'bundling', 'no_auto_abbrev', 'no_ignore_case_always' ], | ||||||||||||||||||||||||||||||||||||||||||
| 188 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | $p->getoptionsfromarray( $cmd, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | \my %wget_options, | ||||||||||||||||||||||||||||||||||||||||||
| 191 | @option_spec, | ||||||||||||||||||||||||||||||||||||||||||
| 192 | ) or return; | ||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | return | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | wantarray ? map { $class->_build_request( $_, \%wget_options, %options ) } @$cmd | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | : ($class->_build_request( $cmd->[0], \%wget_options, %options ))[0] | ||||||||||||||||||||||||||||||||||||||||||
| 197 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | =head2 C<< ->squash_uri( $uri ) >> | ||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | my $uri = HTTP::Request::FromWget->squash_uri( | ||||||||||||||||||||||||||||||||||||||||||
| 205 | URI->new( 'https://example.com/foo/bar/..' ) | ||||||||||||||||||||||||||||||||||||||||||
| 206 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 207 | # https://example.com/foo/ | ||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | Helper method to clean up relative path elements from the URI the same way | ||||||||||||||||||||||||||||||||||||||||||
| 210 | that wget does. | ||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | sub squash_uri( $class, $uri ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
squash_uri: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | my $u = $uri->clone; | |||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | my @segments = $u->path_segments; | |||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | if( $segments[-1] and ($segments[-1] eq '..' or $segments[-1] eq '.' ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$segments[-1] and $segments[-1] eq ".." || $segments[-1] eq "."
$segments[-1] eq ".." or $segments[-1] eq "."
MC/DC0%0/3
$segments[-1] and $segments[-1] eq ".." || $segments[-1] eq "."
$segments[-1]
$segments[-1] eq ".."
$segments[-1] eq "."
Truth table0%0/4
A and B or C
A= $segments[-1]B= $segments[-1] eq ".."C= $segments[-1] eq "."
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | push @segments, ''; | |||||||||||||||||||||||||||||||||||||||||
| 220 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | @segments = grep { $_ ne '.' } @segments; | |||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | # While we find a pair ( "foo", ".." ) remove that pair | ||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | while( grep { $_ eq '..' } @segments ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | while( $i < $#segments ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | if( $segments[$i] ne '..' and $segments[$i+1] eq '..') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$segments[$i] ne ".." and $segments[$i + 1] eq ".."
MC/DC0%0/2
$segments[$i] ne ".." and $segments[$i + 1] eq ".."
$segments[$i] ne ".."
$segments[$i + 1] eq ".."
Truth table0%0/3
A and B
A= $segments[$i] ne ".."B= $segments[$i + 1] eq ".."
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | splice @segments, $i, 2; | |||||||||||||||||||||||||||||||||||||||||
| 230 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | $i++ | |||||||||||||||||||||||||||||||||||||||||
| 232 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 233 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 234 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | if( @segments < 2 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | @segments = ('',''); | |||||||||||||||||||||||||||||||||||||||||
| 238 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | $u->path_segments( @segments ); | |||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | return $u | |||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | # Ugh - wget doesn't allow for multiple headers of the same name on the command line | ||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | sub _add_header( $self, $headers, $h, $value ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_add_header: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | #if( exists $headers->{ $h }) { | ||||||||||||||||||||||||||||||||||||||||||
| 247 | # if (!ref( $headers->{ $h })) { | ||||||||||||||||||||||||||||||||||||||||||
| 248 | # $headers->{ $h } = [ $headers->{ $h }]; | ||||||||||||||||||||||||||||||||||||||||||
| 249 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 250 | # push @{ $headers->{ $h } }, $value; | ||||||||||||||||||||||||||||||||||||||||||
| 251 | #} else { | ||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | $headers->{ $h } = $value; | |||||||||||||||||||||||||||||||||||||||||
| 253 | #} | ||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | ▶ | sub _set_header( $self, $headers, $h, $value ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_header: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | $headers->{ $h } = $value; | |||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | sub _maybe_set_header( $self, $headers, $h, $value ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_maybe_set_header: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | if( ! exists $headers->{ $h }) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | $headers->{ $h } = $value; | |||||||||||||||||||||||||||||||||||||||||
| 263 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | sub _maybe_read_data_file( $self, $read_files, $data ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_maybe_read_data_file: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | my $res; | |||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | if( $read_files ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | open my $fh, '<', $data | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | or die "$data: $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | local $/; # / for Filter::Simple | |||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | binmode $fh; | |||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | $res = <$fh> | |||||||||||||||||||||||||||||||||||||||||
| 274 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | $res = "... contents of $data ..." | |||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | return $res | |||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | ▶ | sub _build_request( $self, $uri, $options, %build_options ) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_request: not called CC=41 SCAR=74.5
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | my $body; | |||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | my @headers = @{ $options->{header} || []}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$options->{'header'} || []
MC/DC0%0/1
$options->{'header'} || []
$options->{'header'}
Truth table0%0/2
A
A= $options->{'header'}
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | my $method = $options->{method}; | |||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | # Ideally, we shouldn't sort the data but process it in-order | ||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | my @post_raw_data; | |||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | if( exists $options->{ 'post-data' }) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | @post_raw_data = $options->{'post-data'}; | |||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | $method = 'POST'; | |||||||||||||||||||||||||||||||||||||||||
| 291 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | if( exists $options->{ 'body-data' }) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | @post_raw_data = $options->{'body-data'}; | |||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | $method ||= 'POST'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$method ||= "POST"
MC/DC0%0/1
$method ||= "POST"
$method
Truth table0%0/2
A
A= $method
| |||||||||||||||||||||||||||||||||||||||||||
| 295 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 296 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | ▶ | if( my $file = $options->{'post-file'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | @post_raw_data = $self->_maybe_read_data_file( $build_options{ read_files }, $file ); | |||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | $method = 'POST'; | |||||||||||||||||||||||||||||||||||||||||
| 300 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | if( my $file = $options->{'body-file'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | @post_raw_data = $self->_maybe_read_data_file( $build_options{ read_files }, $file ); | |||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | ▶ | $method ||= 'POST'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$method ||= "POST"
MC/DC0%0/1
$method ||= "POST"
$method
Truth table0%0/2
A
A= $method
| |||||||||||||||||||||||||||||||||||||||||||
| 304 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 305 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | my @form_args = @{ $options->{form} || []}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$options->{'form'} || []
MC/DC0%0/1
$options->{'form'} || []
$options->{'form'}
Truth table0%0/2
A
A= $options->{'form'}
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||
| 308 | # expand the URI here if wanted | ||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | my @uris = ($uri); | |||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | ▶ | if( ! $options->{ globoff }) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | @uris = map { $_->{url} } generate_requests( pattern => shift @uris, limit => $build_options{ limit } ); | |||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | my @res; | |||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | for my $uri (@uris) { | |||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | $uri = URI->new( $uri ); | |||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | $uri = $self->squash_uri( $uri ); | |||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | ▶ | my $host = $uri->can( 'host_port' ) ? $uri->host_port : "$uri"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | # Stuff we use unless nothing else hits | ||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | my %request_default_headers = %default_headers; | |||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | my $data; | |||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | ▶ | if( @post_raw_data ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | $data = join "&", | |||||||||||||||||||||||||||||||||||||||||
| 327 | @post_raw_data, | ||||||||||||||||||||||||||||||||||||||||||
| 328 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 329 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | ▶ | if( @form_args) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | ▶ | $method ||= 'POST'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$method ||= "POST"
MC/DC0%0/1
$method ||= "POST"
$method
Truth table0%0/2
A
A= $method
| |||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||
| 334 | my $req = HTTP::Request::Common::POST( | ||||||||||||||||||||||||||||||||||||||||||
| 335 | 'https://example.com', | ||||||||||||||||||||||||||||||||||||||||||
| 336 | Content_Type => 'form-data', | ||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | Content => [ map { /^([^=]+)=(.*)$/ ? ($1 => $2) : () } @form_args ], | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 338 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | $body = $req->content; | |||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | $request_default_headers{ 'Content-Type' } = join "; ", $req->headers->content_type; | |||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | } elsif( defined $data ) { | ||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | ▶ | $method ||= 'POST'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$method ||= "POST"
MC/DC0%0/1
$method ||= "POST"
$method
Truth table0%0/2
A
A= $method
| |||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | $body = $data; | |||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | $request_default_headers{ 'Content-Type' } = 'application/x-www-form-urlencoded'; | |||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||
| 347 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | $method ||= 'GET'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$method ||= "GET"
MC/DC0%0/1
$method ||= "GET"
$method
Truth table0%0/2
A
A= $method
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | ▶ | if( defined $body ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | $request_default_headers{ 'Content-Length' } = length $body; | |||||||||||||||||||||||||||||||||||||||||
| 353 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | ▶ | if( $options->{ 'user' } || $options->{'http-user'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$options->{"user"} or $options->{"http-user"}
MC/DC0%0/2
$options->{"user"} or $options->{"http-user"}
$options->{"user"}
$options->{"http-user"}
Truth table0%0/3
A or B
A= $options->{"user"}B= $options->{"http-user"}
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | if( $options->{anyauth} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$options->{"anyauth"} or $options->{"ntlm"} or $options->{"negotiate"}
$options->{"anyauth"} or $options->{"ntlm"}
MC/DC0%0/3
$options->{"anyauth"} or $options->{"ntlm"} or $options->{"negotiate"}
$options->{"anyauth"}
$options->{"ntlm"}
$options->{"negotiate"}
Truth table0%0/4
A or B or C
A= $options->{"anyauth"}B= $options->{"ntlm"}C= $options->{"negotiate"}
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | || $options->{ntlm} | ||||||||||||||||||||||||||||||||||||||||||
| 358 | || $options->{negotiate} | ||||||||||||||||||||||||||||||||||||||||||
| 359 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 360 | # Nothing to do here, just let LWP::UserAgent do its thing | ||||||||||||||||||||||||||||||||||||||||||
| 361 | # This means one additional request to fetch the appropriate | ||||||||||||||||||||||||||||||||||||||||||
| 362 | # 401 response asking for credentials, but ... | ||||||||||||||||||||||||||||||||||||||||||
| 363 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 364 | # $options->{basic} or none at all | ||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | my $info = delete $options->{'user'} || delete $options->{'http-user'}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
delete $options->{'user'} || delete $options->{'http-user'}
MC/DC0%0/2
delete $options->{'user'} || delete $options->{'http-user'}
delete $options->{'user'}
delete $options->{'http-user'}
Truth table0%0/3
A || B
A= delete $options->{'user'}B= delete $options->{'http-user'}
| |||||||||||||||||||||||||||||||||||||||||||
| 366 | # We need to bake this into the header here?! | ||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | push @headers, sprintf 'Authorization: Basic %s', encode_base64( $info ); | |||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||
| 369 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | my %headers; | |||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | for my $kv ( | |||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | ▶ | (map { /^\s*([^:\s]+)\s*:\s*(.*)$/ ? [$1 => $2] : () } @headers),) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | $self->_add_header( \%headers, @$kv ); | |||||||||||||||||||||||||||||||||||||||||
| 375 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | if( defined $options->{ 'user-agent' }) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | $self->_set_header( \%headers, "User-Agent", $options->{ 'user-agent' } ); | |||||||||||||||||||||||||||||||||||||||||
| 379 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | ▶ | if( exists $options->{ 'cache' }) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | ▶ | if(! $options->{ 'cache' } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | $self->_maybe_set_header( \%headers, "Cache-Control" => 'no-cache' ); | |||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | $self->_maybe_set_header( \%headers, "Pragma" => 'no-cache' ); | |||||||||||||||||||||||||||||||||||||||||
| 385 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 386 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | ▶ | if( exists $options->{ 'http-keep-alive' }) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | ▶ | if(! $options->{ 'http-keep-alive' } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | $self->_set_header( \%headers, "Connection" => 'Close' ); | |||||||||||||||||||||||||||||||||||||||||
| 391 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 392 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | ▶ | if( defined $options->{ referer }) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | $self->_set_header( \%headers, "Referer" => $options->{ 'referer' } ); | |||||||||||||||||||||||||||||||||||||||||
| 396 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | # We want to compare the headers case-insensitively | ||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | my %headers_lc = map { lc $_ => 1 } keys %headers; | |||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | for my $k (keys %request_default_headers) { | |||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | ▶ | if( ! $headers_lc{ lc $k }) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | $self->_add_header( \%headers, $k, $request_default_headers{ $k }); | |||||||||||||||||||||||||||||||||||||||||
| 404 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 405 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | $self->_maybe_set_header( \%headers, 'Host' => $host ); | |||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | ▶ | if( defined $options->{ 'cookie-jar' }) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | $options->{'cookie-jar-options'}->{ 'write' } = 1; | |||||||||||||||||||||||||||||||||||||||||
| 410 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | ▶ | if( defined( my $c = $options->{ cookie })) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | ▶ | if( $c =~ /=/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | $headers{ Cookie } = $options->{ 'cookie' }; | |||||||||||||||||||||||||||||||||||||||||
| 415 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | $options->{'cookie-jar'} = $c; | |||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | $options->{'cookie-jar-options'}->{ 'read' } = 1; | |||||||||||||||||||||||||||||||||||||||||
| 418 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 419 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | if( my $c = $options->{ compression }) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | ▶ | if( $c =~ /^(gzip|auto)$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 423 | # my $compressions = HTTP::Message::decodable(); | ||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | $self->_set_header( \%headers, 'Accept-Encoding' => 'gzip' ); | |||||||||||||||||||||||||||||||||||||||||
| 425 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 426 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||
| 428 | push @res, HTTP::Request::CurlParameters->new({ | ||||||||||||||||||||||||||||||||||||||||||
| 429 | method => $method, | ||||||||||||||||||||||||||||||||||||||||||
| 430 | uri => $uri, | ||||||||||||||||||||||||||||||||||||||||||
| 431 | headers => \%headers, | ||||||||||||||||||||||||||||||||||||||||||
| 432 | body => $body, | ||||||||||||||||||||||||||||||||||||||||||
| 433 | maybe local_address => $options->{local_address}, | ||||||||||||||||||||||||||||||||||||||||||
| 434 | maybe cert => $options->{certificate}, | ||||||||||||||||||||||||||||||||||||||||||
| 435 | maybe capath => $options->{'ca-directory'}, | ||||||||||||||||||||||||||||||||||||||||||
| 436 | maybe credentials => $options->{ user }, | ||||||||||||||||||||||||||||||||||||||||||
| 437 | maybe output => $options->{ output }, | ||||||||||||||||||||||||||||||||||||||||||
| 438 | maybe timeout => $options->{ 'max-time' }, | ||||||||||||||||||||||||||||||||||||||||||
| 439 | maybe cookie_jar => $options->{'cookie-jar'}, | ||||||||||||||||||||||||||||||||||||||||||
| 440 | maybe cookie_jar_options => $options->{'cookie-jar-options'}, | ||||||||||||||||||||||||||||||||||||||||||
| 441 | maybe insecure => !$options->{'check-certificate'}, | ||||||||||||||||||||||||||||||||||||||||||
| 442 | maybe show_error => $options->{'show_error'}, | ||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | maybe fail => $options->{'fail'}, | |||||||||||||||||||||||||||||||||||||||||
| 444 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||
| 447 | return @res | ||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||
| 450 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||
| 452 | =head1 LIVE DEMO | ||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||
| 454 | L<https://corion.net/wget2lwp.psgi> | ||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||
| 456 | =head1 KNOWN DIFFERENCES | ||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||
| 458 | =head2 Incompatible cookie jar formats | ||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||
| 460 | Until somebody writes a robust Netscape cookie file parser and proper loading | ||||||||||||||||||||||||||||||||||||||||||
| 461 | and storage for L<HTTP::CookieJar>, this module will not be able to load and | ||||||||||||||||||||||||||||||||||||||||||
| 462 | save files in the format that wget uses. | ||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||
| 464 | =head2 Loading/saving cookie jars is the job of the UA | ||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||
| 466 | You're expected to instruct your UA to load/save cookie jars: | ||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||
| 468 | use Path::Tiny; | ||||||||||||||||||||||||||||||||||||||||||
| 469 | use HTTP::CookieJar::LWP; | ||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||
| 471 | if( my $cookies = $r->cookie_jar ) { | ||||||||||||||||||||||||||||||||||||||||||
| 472 | $ua->cookie_jar( HTTP::CookieJar::LWP->new()->load_cookies( | ||||||||||||||||||||||||||||||||||||||||||
| 473 | path($cookies)->lines | ||||||||||||||||||||||||||||||||||||||||||
| 474 | )); | ||||||||||||||||||||||||||||||||||||||||||
| 475 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||
| 477 | =head2 Different Content-Length for POST requests | ||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||
| 479 | =head2 Different delimiter for form data | ||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||
| 481 | The delimiter is built by L<HTTP::Message>, and C<wget> uses a different | ||||||||||||||||||||||||||||||||||||||||||
| 482 | mechanism to come up with a unique data delimiter. This results in differences | ||||||||||||||||||||||||||||||||||||||||||
| 483 | in the raw body content and the C<Content-Length> header. | ||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||
| 485 | =head1 MISSING FUNCTIONALITY | ||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||
| 487 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||
| 489 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||
| 491 | File uploads / content from files | ||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||
| 493 | While file uploads and reading POST data from files are supported, the content | ||||||||||||||||||||||||||||||||||||||||||
| 494 | is slurped into memory completely. This can be problematic for large files | ||||||||||||||||||||||||||||||||||||||||||
| 495 | and little available memory. | ||||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||
| 498 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||
| 500 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||
| 502 | L<HTTP::Request::AsCurl> - for the inverse function | ||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||
| 504 | The module HTTP::Request::AsCurl likely also implements a much better version | ||||||||||||||||||||||||||||||||||||||||||
| 505 | of C<< ->as_curl >> than this module. | ||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||
| 507 | =head1 REPOSITORY | ||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||
| 509 | The public repository of this module is | ||||||||||||||||||||||||||||||||||||||||||
| 510 | L<http://github.com/Corion/HTTP-Request-FromCurl>. | ||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||
| 512 | =head1 SUPPORT | ||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||
| 514 | The public support forum of this module is | ||||||||||||||||||||||||||||||||||||||||||
| 515 | L<https://perlmonks.org/>. | ||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||
| 517 | =head1 BUG TRACKER | ||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||
| 519 | Please report bugs in this module via the Github bug queue at | ||||||||||||||||||||||||||||||||||||||||||
| 520 | L<https://github.com/Corion/HTTP-Request-FromCurl/issues> | ||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||
| 522 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||
| 524 | Max Maischein C<corion@cpan.org> | ||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||
| 526 | =head1 COPYRIGHT (c) | ||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||
| 528 | Copyright 2018-2026 by Max Maischein C<corion@cpan.org>. | ||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||
| 530 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||||||||||
| 532 | This module is released under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||
| 534 | =cut | ||||||||||||||||||||||||||||||||||||||||||