HTTP::Request::FromTemplate - Create HTTP requests from templates


HTTP-Request-FromTemplate documentation  | view source Contained in the HTTP-Request-FromTemplate distribution.

Index


NAME

Top

HTTP::Request::FromTemplate - Create HTTP requests from templates

SYNOPSIS

Top

  use HTTP::Request::FromTemplate;
  use LWP::UserAgent;

  my $ua = LWP::UserAgent->new();

  # A request, snarfed from your network monitor logs:
  my $template = <<TEMPLATE
  POST http://[% host %][% path %][% query %] HTTP/1.1
  Host: [% host %]
  Connection: keep-alive
  Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
  Accept-Encoding: gzip,deflate
  Accept-Language: en-us,en;q=0.5
  User-Agent: QuickTime (qtver=5.0.2;os=Windows NT 5.1)
  Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
  Keep-Alive: 300
  Referer: http://[% host %][% path %][% query %]

  TEMPLATE
  my $t = HTTP::Request::FromTemplate->new(template => $template);
  my $req = $t->process({ 'host' => 'apple.com',
                          'path' => '/',
                          'query' => '?',
                           });
  my $response = $ua->request($request); # replay the request

ABSTRACT

Top

I wanted this for a long time already. It makes it very convenient to just paste a logged session from the http://livehttpheaders.mozdev.org/|Live HTTP Headers into a template file and be able to faithfully replay a request or to parametrize it without needing to manually compare what is sent against what I want.

PREDEFINED TEMPLATE PARAMETERS

Top

There is one predefined/magic template parameter. content_length will be set to the length of the content (after the template has been filled out) unless it was passed in via the template parameters.

FEEDBACK

Top

This is one of the modules that I created because the idea hit me as crazy but useful. So if you use the module, please tell me what enhancements you'd like, or where it falls short of your expectations.

KNOWN BUGS

Top

* While this module tries to faithfully replicate a HTTP request from a template, it uses HTTP::Request. This means that the order of the headers will be as HTTP::Request thinks and not as your template prescribes.
* Only rudimentary testing has been done.
* The test suite uses Test::Base, which uses Spiffy. I know I will rot in hell for that, but it was so convenient at the time.

Patches are welcome.

REPORTING BUGS

Top

If you find bugs, please report them via http://rt.cpan.org/NoAuth/Bugs.html?Dist=HTTP-Request-FromTemplate or, preferrably via mail to bug-HTTP-Request-FromTemplate@rt.cpan.org.

AUTHOR

Top

Max Maischein (corion@cpan.org)

COPYRIGHT

Top

SEE ALSO

Top

LWP,HTTP::Request,Mozilla Live HTTP Headers


HTTP-Request-FromTemplate documentation  | view source Contained in the HTTP-Request-FromTemplate distribution.