Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Anything wrong with the LWP PUT code

by chanakya (Friar)
on Sep 16, 2010 at 18:37 UTC ( #860382=perlquestion: print w/replies, xml ) Need Help??

chanakya has asked for the wisdom of the Perl Monks concerning the following question:

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 ?

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
    MIME includes information on the Content-disposition which you'll need and refers you to the relevant RFCs for lots of MIME-related issues. It's not a Perl code issue but a data content issue.
Re: Anything wrong with the LWP PUT code
by Anonymous Monk on Sep 16, 2010 at 21:01 UTC
    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 ?

    What does the RFC specify?

Re: Anything wrong with the LWP PUT code
by chanakya (Friar) on Sep 17, 2010 at 07:10 UTC
    Thank you everyone, I have figured out the issue.
    For the interested a PUT request should have the filename as shown http://xxxx/testput/PPut/abc.gz .

    Once I appended the $ENV{'PATH_INFO'} to my PUT url , everything started working as expected.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://860382]
Approved by superfrink
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2022-12-03 22:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?