in reply to Test HTTP::Daemon

For some reason, you have to call get_request() before you send an error. (You have to know what the client wants before you can tell it no, perhaps.) Here's what I ended up with:
#!/usr/bin/perl -w use strict; use HTTP::Daemon; use HTTP::Status; my $d=HTTP::Daemon->new(LocalAddr=>'localhost',LocalPort=>'6666', Reus +e => '1') || die "Can't create daemon: $!"; my $nd; while(1) { $nd=$d->accept; my $r = $nd->get_request(); $nd->send_error(RC_FORBIDDEN); $nd->close; }
Otherwise, it gave me an undefined value error in HTTP::Daemon (the sub where it checks for a HTTP version less than 1.0. Odd.) Putting in the my $r = $nd->get_request() line fixed everything right up.

Replies are listed 'Best First'.
RE: Re: Test HTTP::Daemon
by btrott (Parson) on Apr 19, 2000 at 19:42 UTC
    chromatic wrote:
    > Otherwise, it gave me an undefined value error in > HTTP::Daemon (the sub where it checks for a HTTP version > less than 1.0. Odd.) Putting in the my $r = > $nd->get_request() line fixed everything right up.
    The reason you're probably getting that undefined error is because the HTTP version is sent in the request, like
    GET /foo HTTP/1.0
    So, internally, when that request gets read in, HTTP::Daemon probably reads the HTTP version and does the checking to see if it's greater than 1.0. If you've never received a request, that value isn't set, thus you get an unitialized value warning.