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 bind : $@\n"; # print "Please contact me at: url, ">\n"; while (my $c = $d->accept) { while (my $r = $c->get_request) { # if the below print goes, then the image is served correctly 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|jpg|bmp|png)/)) { open (IMAGE, 'C:\\rrships' . $r->url->path) or warn 'Couldn\'t open image: ' . $r->url->path; my $response = HTTP::Response->new(200); $response->push_header('Content-Type','image/' . $1); my $content = ''; while () { $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); }