Hello, the attached patch fixes two bugs triggered when empty content is
returned:
1. two warnings showed up on STDERR (examples below)
2. I was oddly prompted to download a file of type "BIN". That was
because the MIME-type had been set to "application/octet-stream".
(That's how File::MMagic says "I don't know" ).
Thanks!
Mark
Use of uninitialized value in length at lib/HTTP/Server/Simple/Static.pm
line 46.
Use of uninitialized value in print at lib/HTTP/Server/Simple/Static.pm
line 47.
Subject: | simple_static_no_content.patch |
--- /usr/local/share/perl/5.8.8/HTTP/Server/Simple/Static.pm 2006-11-06 04:43:00.000000000 -0500
+++ lib/HTTP/Server/Simple/Static.pm 2007-07-21 14:00:33.000000000 -0400
@@ -37,8 +37,16 @@
$fh->close;
my $mimeobj = $mime->mimeTypeOf($path);
- my $mime = ($mimeobj ? $mimeobj->type :
- $magic->checktype_contents($content));
+ my $mime = $mimeobj->type if $mimeobj;
+
+ if (defined $content) {
+ $mime ||= $magic->checktype_contents($content);
+ }
+ # No content defined? Use some sane defaults
+ else {
+ $content = '';
+ $mime = 'text/plain';
+ }
use bytes; # Content-Length in bytes, not characters
print "HTTP/1.1 200 OK\015\012";