… | |
… | |
73 | use HTTP::Date; |
73 | use HTTP::Date; |
74 | use Convert::Scalar 'weaken'; |
74 | use Convert::Scalar 'weaken'; |
75 | |
75 | |
76 | our %conn; # $conn{ip}{fh} => connobj |
76 | our %conn; # $conn{ip}{fh} => connobj |
77 | our %blocked; |
77 | our %blocked; |
|
|
78 | our %mimetype; |
|
|
79 | |
|
|
80 | sub 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 | |
79 | sub new { |
93 | sub 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; |
… | |
… | |
383 | ignore: |
397 | ignore: |
384 | } else { |
398 | } else { |
385 | ($l, $h) = (0, $length - 1); |
399 | ($l, $h) = (0, $length - 1); |
386 | } |
400 | } |
387 | |
401 | |
388 | if ($self->{path} =~ /\.html$/) { |
402 | $self->{path} =~ /\.([^.]+)$/; |
389 | $hdr->{"Content-Type"} = "text/html"; |
|
|
390 | } else { |
|
|
391 | $hdr->{"Content-Type"} = "application/octet-stream"; |
403 | $hdr->{"Content-Type"} = $mimetype{lc $1} || "application/octet-stream"; |
392 | } |
|
|
393 | |
|
|
394 | $hdr->{"Content-Length"} = $length; |
404 | $hdr->{"Content-Length"} = $length; |
395 | |
405 | |
396 | $self->response(@code, $hdr, ""); |
406 | $self->response(@code, $hdr, ""); |
397 | |
407 | |
398 | if ($self->{method} eq "GET") { |
408 | if ($self->{method} eq "GET") { |