home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / g-request < prev    next >
Encoding:
Text File  |  2001-01-18  |  1.9 KB  |  91 lines

  1. #!/usr/bin/perl -w
  2. use HTTP::GHTTP;
  3. use Getopt::Long;
  4. $|=1;
  5. use strict;
  6. use vars qw/$VERSION/;
  7.  
  8. $VERSION = '1.0';
  9.  
  10. my @getopt_args = qw(
  11.         p=s  P   H=s@   u   U
  12.         s    e      d   v
  13.         h    V
  14.         );
  15.  
  16. my %options;
  17.  
  18. Getopt::Long::config("noignorecase", "bundling");
  19. unless (GetOptions(\%options, @getopt_args)) {
  20.     usage();
  21. }
  22.  
  23. if ($options{V}) {
  24.     print <<EOT;
  25. This is g-request version $VERSION
  26.  
  27. Copyright 2000, AxKit.com Ltd
  28.  
  29. EOT
  30. }
  31.  
  32. usage() if $options{h} || !@ARGV;
  33.  
  34. $options{u} = 1 if $options{U};
  35.  
  36. unless($options{P}) {
  37.     $options{p} ||= $ENV{http_proxy};
  38. }
  39.  
  40. my $r = HTTP::GHTTP->new();
  41.  
  42. $r->set_header(Connection => 'close');
  43.  
  44. for my $extra_header (@{ $options{H} || [] }) {
  45.     my ($name, $value) = split /:\s*/, $extra_header, 2;
  46.     $r->set_header($name, $value);
  47. }
  48.  
  49. $r->set_proxy($ENV{http_proxy}) if $ENV{http_proxy} && !$options{P};
  50. $r->set_proxy($options{p}) if $options{p};
  51.  
  52. my $URI = shift @ARGV;
  53.  
  54. $r->set_uri($URI);
  55.  
  56. $r->process_request();
  57.  
  58. if ($options{e}) {
  59.     eval {
  60.         my @headers = $r->get_headers;
  61.         print join("\n", map { "$_: " . $r->get_header($_) } @headers), "\n\n";
  62.     };
  63.     if ($@) {
  64.         warn $@, "\n", "get_headers (and thus -e) only available in libghttp 1.08 and higher";
  65.     }
  66. }
  67.  
  68. unless ($options{d}) {
  69.     print $r->get_body();
  70. }
  71.  
  72. sub usage {
  73.     print <<EOT;
  74. Usage: g-request [-options] <url>
  75.     -p <proxy>    Use this as a proxy server
  76.     -P            Don't pick up proxy settings from environment
  77.     -H <header>   Send this HTTP header (you can specify several)
  78.     -u            Display method and URL before any response
  79.     -U            Display request headers (implies -u)
  80.     -s            Display response status code
  81.     -e            Display response headers
  82.     -d            Do not display content
  83.     -v            Be verbose
  84.     -h            Print this help message
  85.     -V            Show program version
  86. EOT
  87.     exit; #'
  88. }
  89.  
  90. exit(0);
  91.