bkiahg has asked for the wisdom of the Perl Monks concerning the following question:
use strict; $SIG{'PIPE'} = 'IGNORE'; use HTTP::Daemon; use HTTP::Status; require 'C:\\rrships\\default.cgi'; my $d = HTTP::Daemon->new(Listen => 5, LocalAddr => 'localhost', LocalPort => 80, Proto => 'tcp') or die "Can't bin +d : $@\n"; # print "Please contact me at: <URL:", $d->url, ">\n"; while (my $c = $d->accept) { while (my $r = $c->get_request) { # if the below print goes, then the image is served correctl +y print $r->method . ' ' . $r->url->path . "\n"; if (($r->method eq 'GET') && ($r->url->path =~ m/\.(html|cgi +|htm|pl)/)) { my $response = HTTP::Response->new(200); $response->content(&Hello_World($r->url->path, $r->url-> +query)); $response->header("Content-Type" => "text/html"); $c->send_response($response); } elsif (($r->method eq 'GET') && ($r->url->path =~ m/\.(gif|j +pg|bmp|png)/)) { open (IMAGE, 'C:\\rrships' . $r->url->path) or warn 'Cou +ldn\'t open image: ' . $r->url->path; my $response = HTTP::Response->new(200); $response->push_header('Content-Type','image/' . $1); my $content = ''; while (<IMAGE>) { $content .= $_; } close IMAGE; $response->content($content); $c->send_response($response); } elsif (($r->method eq 'GET') && ($r->url->path eq '/')) { my $response = HTTP::Response->new(200); $response->content(&Hello_World($r->url->path, $r->url-> +query)); $response->header("Content-Type" => "text/html"); $c->send_response($response); } else { $c->send_error(RC_FORBIDDEN); } } $c->close; undef($c); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: HTTP::Daemon Pipe Breaking
by Illuminatus (Curate) on Jan 13, 2009 at 22:42 UTC | |
by bkiahg (Pilgrim) on Jan 14, 2009 at 02:24 UTC |