Dear Monks
I have been developing the Perl script to handle PUT requests. The script reads the incoming CURL requests which has
binary data and raises a PUT request to a specified url (http://xxxx/testput/PPut/).
I'm able to send the headers and the binary data to the PUT url, but have noticed an issue with the final file written.
.
If the client has sent abc.gz, then the final file written is PPut.gz, instead of abc.gz. I have checked the content of Put.gz has
the same content of abc.gz.
Is there anything wrong I'm doing in the code.
Below is the curl requests which are used for testing
curl -T abc.gz -X PUT -H "User-Agent: MyUA" http://xxxx.com/cgi-bin/ha
+ndleput.cgi -v
and the Perl code (handleput.cgi) that forwards the curl request to the url specified.
#!/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
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 ?
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.