Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-19 23:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found