in reply to Re: Are all .cgi helper modules unfit for http methods common in REST?
in thread Are all .cgi helper modules unfit for http methods common in REST?

Puh, test scripts basically done. Still, the test-server seems to refuse to serve PROPFIND requests. I don't know if this is HTTP::Server::Simple or something else, yet. But again - this "we don't like lesser known methods" sucks..

What already can be observed is that CGI.pm strangely parses PUT data into a 'keywords' param(). (??)

Minor update to the code: uncommenting the CGI::Simple part should enable you to see how CGI::Simple beahves, but for me it simply hangs. I'm giving up for today...

test-client.pl
#perl use LWP::UserAgent; use HTTP::Request; my $ua = LWP::UserAgent->new; ## build request print "PROPFIND:\n"; $req = HTTP::Request->new('PROPFIND' => 'http://localhost:4242/'); $req->header( 'Depth' => '1' ); $req->content('<?xml version="1.0" encoding="utf-8" ?> <D:propfind xmlns:D="DAV:"> <D:prop> <D:creationdate/> <D:displayname/> <D:getcontentlength/> <D:getcontenttype/> <D:getetag/> <D:getlastmodified/> <D:resourcetype/> </D:prop> </D:propfind>'); ## fire request through ua and get a response back my $res = $ua->request($req); if ($res->is_success) { print $res->status_line ."\n". $res->headers->as_string . $res-> +content; }else{ print $res->status_line, "\n"; } print "\n\n"; ## build request print "PUT:\n"; $req = HTTP::Request->new('PUT' => 'http://localhost:4242/test.txt'); +## update $req->content('1234567890'); ## Pass request to the user agent and get a response back my $res = $ua->request($req); if ($res->is_success) { print $res->status_line ."\n". $res->headers->as_string . $res-> +content; }else{ print $res->status_line, "\n"; } print "\n\n";
a testapp.pm
package testapp; use base 'CGI::Application'; use Data::Dumper; sub setup { my $self = shift; $self->start_mode('index'); $self->run_modes('index' => 'index'); } ## update # sub cgiapp_get_query { # my $self = shift; # require CGI::Simple; # return CGI::Simple->new(); # } sub index { my $self = shift; return '<pre>'.Dumper($self); } 1;
and the server to run it:
#!/usr/bin/perl use CGI::Application::Server; use testapp; my $server = CGI::Application::Server->new(4242); # $server->document_root('./htdocs'); $server->entry_points({ '/' => 'testapp', '/test.txt' => 'testapp', }); $server->run();

Replies are listed 'Best First'.
Re^3: Are all .cgi helper modules unfit for http methods common in REST?
by derby (Abbot) on Aug 13, 2010 at 01:26 UTC

    If you're getting keyword set when processing a PUT request than your code (or HTTP::Request) is setting the content-type of the request to either multipart/form-data or application/x-www-form-urlencoded. You should set the content-type to something else (maybe text/xml).

    -derby
      That makes sense. So my requests were faulty.. 1:0 for CGI.pm
      Tested this with my test-client.pl script here, and as you said, doing PUTs with a proper header does lead to CGI.pm parsing out PUTPARAM. (As a sidenote, what will CGI.pm parse out on other methods like PROPFIND? PROPFINDDATA??)

      Problem is, if you intend to use this all here for WebDAV, you can't control the clients behaving nicely. For example, gvfs, GNOME's DAV client - as I see it - does not set any headers on requests...
        As a sidenote, what will CGI.pm parse out on other methods like PROPFIND? PROPFINDDATA??)

        Should be easy to find out :p