@@ -267,11 +267,12 @@ my @getopt_args = (
267267 ' C=s' , # credentials for basic authorization
268268 ' H=s@' , # extra headers, form "Header: value string"
269269 #
270- ' u' , # display method, URL and headers of request
270+ ' u' , # display method and URL of request
271271 ' U' , # display request headers also
272272 ' s' , # display status code
273273 ' S' , # display whole chain of status codes
274274 ' e' , # display response headers (default for HEAD)
275+ ' E' , # display whole chain of headers
275276 ' d' , # don't display content
276277 #
277278 ' h' , # print usage
@@ -322,12 +323,22 @@ elsif (!defined $allowed_methods{$method}) {
322323 die " $progname : $method is not an allowed method\n " ;
323324}
324325
326+ if ($options {' S' } || $options {' E' }) {
327+ $options {' U' } = 1 if $options {' E' };
328+ $options {' E' } = 1 if $options {' e' };
329+ $options {' s' } = 1;
330+ $options {' u' } = 1;
331+ }
332+
325333if ($method eq " HEAD" ) {
326334 $options {' s' } = 1;
327335 $options {' e' } = 1 unless $options {' d' };
328336 $options {' d' } = 1;
329337}
330338
339+ $options {' u' } = 1 if $options {' U' };
340+ $options {' s' } = 1 if $options {' e' };
341+
331342if (defined $options {' t' }) {
332343 $options {' t' } =~ / ^(\d +)([smh])?/ ;
333344 die " $progname : Illegal timeout value!\n " unless defined $1 ;
@@ -391,6 +402,15 @@ if ($options{'c'}) { # will always be set for request that wants content
391402
392403$errors = 0;
393404
405+ sub show {
406+ my $r = shift ;
407+ my $last = shift ;
408+ print $method , " " , $r -> request-> uri-> as_string, " \n " if $options {' u' };
409+ print $r -> request-> headers_as_string, " \n " if $options {' U' };
410+ print $r -> status_line, " \n " if $options {' s' };
411+ print $r -> headers_as_string, " \n " if $options {' E' } or $last ;
412+ }
413+
394414# Ok, now we perform the requests, one URL at a time
395415while ($url = shift ) {
396416 # Create the URL object, but protect us against bad URLs
@@ -416,28 +436,12 @@ while ($url = shift) {
416436 $request -> uri($url );
417437 $response = $ua -> request($request );
418438
419- if ($options {' u' } || $options {' U' }) {
420- my $url = $response -> request-> uri-> as_string;
421- print " $method $url \n " ;
422- print $response -> request-> headers_as_string, " \n " if $options {' U' };
423- }
424-
425439 if ($options {' S' }) {
426- for my $r ($response -> redirects, $response ) {
427- my $method = $r -> request-> method;
428- my $url = $r -> request-> uri-> as_string;
429- print " $method $url --> " , $r -> status_line, " \n " ;
440+ for my $r ($response -> redirects) {
441+ show($r );
430442 }
431443 }
432- elsif ($options {' s' }) {
433- print $response -> status_line, " \n " ;
434- }
435-
436- if ($options {' e' }) {
437- # Display headers
438- print $response -> headers_as_string;
439- print " \n " ; # separate headers and content
440- }
444+ show($response , $options {' e' });
441445
442446 unless ($options {' d' }) {
443447 if ($options {' o' } &&
@@ -524,6 +528,7 @@ Usage: $progname [-options] <url>...
524528 -s Display response status code
525529 -S Display response status chain
526530 -e Display response headers
531+ -E Display whole chain of headers
527532 -d Do not display content
528533 -o <format> Process HTML content in various ways
529534
0 commit comments