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

#!/usr/bin/perl use HTTP::Daemon; use HTTP::Status; $d=HTTP::Daemon->new(LocalAddr=>'localhost',LocalPort=>6666); while(1) { $nd=$d->accept; $nd->send_error(RC_FORBIDDEN); }
I test the HTTP::Daemon module,but it didn't output the
Error message to me.Can you tell me where is my fault?
Thank you.

Edited 15 Jul 01, 08:45 pm (PDT) by footpad

Replies are listed 'Best First'.
Re: Test HTTP::Daemon
by chromatic (Archbishop) on Apr 19, 2000 at 19:38 UTC
    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.
      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.