chanakya has asked for the wisdom of the Perl Monks concerning the following question:
and the Perl code (handleput.cgi) that forwards the curl request to the url specified.curl -T abc.gz -X PUT -H "User-Agent: MyUA" http://xxxx.com/cgi-bin/ha +ndleput.cgi -v
Do I need to add the filename from $ENV{'PATH_INFO'} to the PPut url, so the final created will be abc.gz instead of PPut.gz ?#!/usr/bin/perl -w use LWP::UserAgent; use HTTP::Request; use HTTP::Response; use HTTP::Headers; use HTTP::Status qw(:constants :is status_message); use CGIWrapper; ##instance for CGI my $url = 'http://xxxx/testput/PPut'; main(); exit(0); sub main() { my $cgi = new CGIWrapper(); my $ua = LWP::UserAgent->new; my %headers = map { $_ => $cgi->http($_) } $cgi->http; my $req_headers = HTTP::Headers->new( %headers ); my $readData = sub { read(STDIN, my $buf, 65536); return $buf; }; $req = HTTP::Request->new("PUT", $url, $req_headers, $readData) if + ($ENV{'REQUEST_METHOD'} eq 'PUT'); print STDOUT $cgi->header(-type=>'text/plain'); print STDOUT $req->as_string(),"\n"; $res = $ua->request($req); if($res->is_success) { print STDOUT $res->code,' ', $res->message,"\n"; } else{ print STDOUT $res->status_line, "\n"; } } Below are the headers captured by the above script: <code> PUT http://xxxx/testput/PPut Cache-Control: no-store Connection: close Expect: 100-continue User-Agent: MyUA Content-Length: 248329 Content-Type: application/x-gzip-compressed Request-Method: PUT PATH-INFO: /abc.gz
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Anything wrong with the LWP PUT code
by mr_mischief (Monsignor) on Sep 17, 2010 at 01:07 UTC | |
|
Re: Anything wrong with the LWP PUT code
by Anonymous Monk on Sep 16, 2010 at 21:01 UTC | |
|
Re: Anything wrong with the LWP PUT code
by chanakya (Friar) on Sep 17, 2010 at 07:10 UTC |