Add built local::lib
[catagits/Gitalist.git] / local-lib5 / bin / lwp-dump
1 #!/usr/bin/perl -w
2
3 eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}'
4     if 0; # not running under some shell
5
6 use strict;
7 use LWP::UserAgent ();
8 use Getopt::Long qw(GetOptions);
9
10 my $VERSION = "5.827";
11
12 GetOptions(\my %opt,
13     'parse-head',
14     'max-length=n',
15     'keep-client-headers',
16     'method=s',
17     'agent=s',
18 ) || usage();
19
20 my $url = shift || usage();
21 @ARGV && usage();
22
23 sub usage {
24     (my $progname = $0) =~ s,.*/,,;
25     die <<"EOT";
26 Usage: $progname [options] <url>
27
28 Recognized options are:
29    --agent <str>
30    --keep-client-headers
31    --max-length <n>
32    --method <str>
33    --parse-head
34
35 EOT
36 }
37
38 my $ua = LWP::UserAgent->new(
39     parse_head => $opt{'parse-head'} || 0,
40     keep_alive => 1,
41     env_proxy => 1,
42     agent => $opt{agent} || "lwp-dump/$VERSION ",
43 );
44
45 my $req = HTTP::Request->new($opt{method} || 'GET' => $url);
46 my $res = $ua->simple_request($req);
47 $res->remove_header(grep /^Client-/, $res->header_field_names)
48     unless $opt{'keep-client-headers'} or
49         ($res->header("Client-Warning") || "") eq "Internal response";
50
51 $res->dump(maxlength => $opt{'max-length'});
52
53 __END__
54
55 =head1 NAME
56
57 lwp-dump - See what headers and content is returned for a URL
58
59 =head1 SYNOPSIS
60
61 B<lwp-dump> [ I<options> ] I<URL>
62
63 =head1 DESCRIPTION
64
65 The B<lwp-dump> program will get the resource indentified by the URL and then
66 dump the response object to STDOUT.  This will display the headers returned and
67 the initial part of the content, escaped so that it's safe to display even
68 binary content.  The escapes syntax used is the same as for Perl's double
69 quoted strings.  If there is no content the string "(no content)" is shown in
70 its place.
71
72 The following options are recognized:
73
74 =over
75
76 =item B<--agent> I<str>
77
78 Override the user agent string passed to the server.
79
80 =item B<--keep-client-headers>
81
82 LWP internally generate various C<Client-*> headers that are stripped by
83 B<lwp-dump> in order to show the headers exactly as the server provided them.
84 This option will suppress this.
85
86 =item B<--max-length> I<n>
87
88 How much of the content to show.  The default is 512.  Set this
89 to 0 for unlimited.
90
91 If the content is longer then the string is chopped at the
92 limit and the string "...\n(### more bytes not shown)"
93 appended.
94
95 =item B<--method> I<str>
96
97 Use the given method for the request instead of the default "GET".
98
99 =item B<--parse-head>
100
101 By default B<lwp-dump> will not try to initialize headers by looking at the
102 head section of HTML documents.  This option enables this.  This corresponds to
103 L<LWP::UserAgent/"parse_head">.
104
105 =back
106
107 =head1 SEE ALSO
108
109 L<lwp-request>, L<LWP>, L<HTTP::Message/"dump">
110