ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/myhttpd/httpd.pl
(Generate patch)

Comparing Coro/myhttpd/httpd.pl (file contents):
Revision 1.6 by root, Fri Aug 10 21:03:41 2001 UTC vs.
Revision 1.9 by root, Sat Aug 11 12:49:21 2001 UTC

73use HTTP::Date; 73use HTTP::Date;
74use Convert::Scalar 'weaken'; 74use Convert::Scalar 'weaken';
75 75
76our %conn; # $conn{ip}{fh} => connobj 76our %conn; # $conn{ip}{fh} => connobj
77our %blocked; 77our %blocked;
78our %mimetype;
79
80sub read_mimetypes {
81 local *M;
82 if (open M, "<mimetypes") {
83 while (<M>) {
84 if (/^([^#]\S+)\t+(\S+)$/) {
85 $mimetype{lc $1} = $2;
86 }
87 }
88 } else {
89 $self->slog(1, "cannot open mimetypes\n");
90 }
91}
78 92
79sub new { 93sub new {
80 my $class = shift; 94 my $class = shift;
81 my $peername = shift; 95 my $peername = shift;
82 my $fh = shift; 96 my $fh = shift;
83 my $self = bless { fh => $fh }, $class; 97 my $self = bless { fh => $fh }, $class;
84 my (undef, $iaddr) = unpack_sockaddr_in $peername 98 my (undef, $iaddr) = unpack_sockaddr_in $peername
85 or $self->err(500, "unable to decode peername"); 99 or $self->err(500, "unable to decode peername");
100
86 $self->{remote_addr} = inet_ntoa $iaddr; 101 $self->{remote_addr} = inet_ntoa $iaddr;
87 102
88 # enter ourselves into various lists 103 # enter ourselves into various lists
89 weaken ($conn{$self->{remote_addr}}{$self*1} = $self); 104 weaken ($conn{$self->{remote_addr}}{$self*1} = $self);
90 105
244 259
245 $self->{name} = $uri; 260 $self->{name} = $uri;
246 261
247 # now do the path mapping 262 # now do the path mapping
248 $self->{path} = "$::DOCROOT/$host$uri"; 263 $self->{path} = "$::DOCROOT/$host$uri";
264
265 $self->access_check;
249} 266}
250 267
251sub server_address { 268sub server_address {
252 my $self = shift; 269 my $self = shift;
253 my ($port, $iaddr) = unpack_sockaddr_in $self->{fh}->getsockname 270 my ($port, $iaddr) = unpack_sockaddr_in $self->{fh}->getsockname
380ignore: 397ignore:
381 } else { 398 } else {
382 ($l, $h) = (0, $length - 1); 399 ($l, $h) = (0, $length - 1);
383 } 400 }
384 401
385 if ($self->{path} =~ /\.html$/) { 402 $self->{path} =~ /\.([^.]+)$/;
386 $hdr->{"Content-Type"} = "text/html";
387 } else {
388 $hdr->{"Content-Type"} = "application/octet-stream"; 403 $hdr->{"Content-Type"} = $mimetype{lc $1} || "application/octet-stream";
389 }
390
391 $hdr->{"Content-Length"} = $length; 404 $hdr->{"Content-Length"} = $length;
392 405
393 $self->response(@code, $hdr, ""); 406 $self->response(@code, $hdr, "");
394 407
395 if ($self->{method} eq "GET") { 408 if ($self->{method} eq "GET") {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines