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 ?

In reply to Anything wrong with the LWP PUT code by chanakya

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.