|
NAMEHTTP::Proxy::BodyFilter::save - A filter that saves transferred data to a fileSYNOPSISuse HTTP::Proxy; use HTTP::Proxy::BodyFilter::save; my $proxy = HTTP::Proxy->new; # save RFC files as we browse them $proxy->push_filter( path => qr!/rfc\d+.txt!, mime => 'text/plain', response => HTTP::Proxy::BodyFilter::save->new( template => '%f', prefix => 'rfc', keep_old => 1, ) ); $proxy->start; DESCRIPTIONThe HTTP::Proxy::BodyFilter::save filter can save HTTP messages (responses or request) bodies to files. The name of the file is determined by a template and the URI of the request.Simply insert this filter in a filter stack, and it will save the data as it flows through the proxy. Depending on where the filter is located in the stack, the saved data can be more or less modified. This filter will create directories if it needs to! Note: Remember that the default "mime" parameter for "push_filter()" is "text/*" and that you may need to change it for other MIME types. ConstructorThe constructor accepts quite a few options. Most of them control the construction of the filename that will be used to save the response body. There are two options to compute this filename:
The template option uses the following options:
Using your own subroutine is also possible, with the following parameter:
Other options help the filter decide where and when to save:
ExamplesGiven a request for the <http://search.cpan.org/dist/HTTP-Proxy/> URI, the filename is computed as follows, depending on the constructor options:No options -> search.cpan.org/dist/HTTP-Proxy/index.html no_host => 1 -> dist/HTTP-Proxy/index.html no_dirs => 1 -> search.cpan.org/index.html no_host => 1, no_dirs => 1, prefix => 'data' -> data/index.html cut_dirs => 1 -> search.cpan.org/HTTP-Proxy/index.html cut_dirs => 2 -> search.cpan.org/index.html METHODSThis filter implements several methods, which are all called automatically:
SEE ALSOHTTP::Proxy, HTTP::Proxy::BodyFilter.AUTHORPhilippe "BooK" Bruhat, <book@cpan.org>.ACKNOWLEDGMENTSThanks to Mat Proud for asking how to store all pages which go through the proxy to disk, without any processing. The further discussion we had led to the writing of this class.Wget(1) provided the inspiration for many of the file naming options. Thanks to Nicolas Chuche for telling me about "O_EXCL". Thanks to Rafaël Garcia-Suarez and David Rigaudiere for their help on irc while coding the nasty "begin()" method. ";-)" Thanks to Howard Jones for the inspiration and initial patch for the "filename" option. Lucas Gonze provided a patch to make "status" actually work. Thanks to Max Maischein for detecting a bug in the parameter validation for "filename" (<http://rt.cpan.org/Ticket/Display.html?id=14548>). Thanks to Mark Tilford, who found out that the "filename" option was incorrectly used internally (<http://rt.cpan.org/Ticket/Display.html?id=18644>). Thanks to Roland Stigge and Gunnar Wolf for reporting and forwarding Debian bug #433951 to CPAN RT (<http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=433951>, <http://rt.cpan.org/Ticket/Display.html?id=33018>). COPYRIGHTCopyright 2004-2015, Philippe Bruhat.LICENSEThis module is free software; you can redistribute it or modify it under the same terms as Perl itself.
Visit the GSP FreeBSD Man Page Interface. |