--- Server.pm 2005/03/12 04:40:16 1.5
+++ Server.pm 2005/03/13 16:50:52
@@ -2,7 +2,7 @@
use strict;
use warnings;
use File::Slurp;
-use Encode qw(encode_utf8);
+use Encode;
use File::Find::Rule::Filesys::Virtual;
use HTTP::Date;
use HTTP::Headers;
@@ -45,7 +45,7 @@
my $fs = $self->filesys || die 'Boom';
my $method = $request->method;
- my $path = uri_unescape($request->uri->path);
+ my $path = decode_utf8 uri_unescape $request->uri->path;
if (!defined $response) {
$response = HTTP::Response->new;
@@ -68,19 +68,17 @@
sub options {
my($self, $request, $response) = @_;
- #no warnings;
- #$response->headers->header('DAV' => [qw(1,2 <
http://apache.org/dav/propset/fs/1>)]); # Nautilus freaks out
- $response->headers->header('DAV' => '1,2,<
http://apache.org/dav/propset/fs/1>'); # Nautilus freaks out
- $response->headers->header('MS-Author-Via' => 'DAV'); # Nautilus freaks out
- $response->headers->header('Allow' => join(',', map {uc} keys %implemented));
- $response->headers->header('Content-Type' => 'httpd/unix-directory');
- $response->headers->header('Keep-Alive' => 'timeout=15, max=96');
+ $response->header('DAV' => '1,2,<
http://apache.org/dav/propset/fs/1>'); # Nautilus freaks out
+ $response->header('MS-Author-Via' => 'DAV'); # Nautilus freaks out
+ $response->header('Allow' => join(',', map {uc} keys %implemented));
+ $response->header('Content-Type' => 'httpd/unix-directory');
+ $response->header('Keep-Alive' => 'timeout=15, max=96');
return $response;
}
sub head {
my($self, $request, $response) = @_;
- my $path = uri_unescape($request->uri->path);
+ my $path = decode_utf8 uri_unescape $request->uri->path;
my $fs = $self->filesys;
if ($fs->test("f", $path) && $fs->test("r", $path)) {
@@ -90,7 +88,7 @@
} elsif ($fs->test("d", $path)) {
# a web browser, then
my @files = $fs->list($path);
- $response->header('Content-Type', 'text/html');
+ $response->header('Content-Type' => 'text/html; charset="utf-8"');
} else {
$response = HTTP::Response->new(404, "NOT FOUND", $response->headers);
}
@@ -99,28 +97,28 @@
sub get {
my($self, $request, $response) = @_;
- my $path = uri_unescape($request->uri->path);
+ my $path = decode_utf8 uri_unescape $request->uri->path;
my $fs = $self->filesys;
- if ($fs->test("f", $path) && $fs->test("r", $path)) {
+ if ($fs->test('f', $path) && $fs->test('r', $path)) {
my $fh = $fs->open_read($path);
my $file = join '', <$fh>;
$fs->close_read($fh);
$response->content($file);
$response->last_modified($fs->modtime($path));
- } elsif ($fs->test("d", $path)) {
+ } elsif ($fs->test('d', $path)) {
# a web browser, then
my @files = $fs->list($path);
my $body;
foreach my $file (@files) {
- if ($fs->test("d", "$path$file")) {
+ if ($fs->test('d', $path . $file)) {
$body .= qq|<a href="$file/">$file/</a><br>\n|;
} else {
$file =~ s{/$}{};
$body .= qq|<a href="$file">$file</a><br>\n|;
}
}
- $response->header('Content-Type' => 'text/html');
+ $response->header('Content-Type' => 'text/html; charset="utf-8"');
$response->content($body);
} else {
$response->code(404);
@@ -131,7 +129,7 @@
sub put {
my($self, $request, $response) = @_;
- my $path = uri_unescape($request->uri->path);
+ my $path = decode_utf8 uri_unescape $request->uri->path;
my $fs = $self->filesys;
$response = HTTP::Response->new(201, "CREATED", $response->headers);
@@ -153,7 +151,7 @@
sub delete {
my($self, $request, $response) = @_;
- my $path = uri_unescape($request->uri->path);
+ my $path = decode_utf8 uri_unescape $request->uri->path;
my $fs = $self->filesys;
unless ($fs->test("e", $path)) {
@@ -200,7 +198,7 @@
sub copy {
my($self, $request, $response) = @_;
- my $path = uri_unescape($request->uri->path);
+ my $path = decode_utf8 uri_unescape $request->uri->path;
my $fs = $self->filesys;
my $destination = $request->header('Destination');
@@ -268,7 +266,7 @@
sub copy_file {
my($self, $request, $response) = @_;
- my $path = uri_unescape($request->uri->path);
+ my $path = decode_utf8 uri_unescape $request->uri->path;
my $fs = $self->filesys;
my $destination = $request->header('Destination');
@@ -327,7 +325,7 @@
sub lock {
my($self, $request, $response) = @_;
- my $path = uri_unescape($request->uri->path);
+ my $path = decode_utf8 uri_unescape $request->uri->path;
my $fs = $self->filesys;
$fs->lock($path);
@@ -337,7 +335,7 @@
sub unlock {
my($self, $request, $response) = @_;
- my $path = uri_unescape($request->uri->path);
+ my $path = decode_utf8 uri_unescape $request->uri->path;
my $fs = $self->filesys;
$fs->unlock($path);
@@ -347,7 +345,7 @@
sub mkcol {
my($self, $request, $response) = @_;
- my $path = uri_unescape($request->uri->path);
+ my $path = decode_utf8 uri_unescape $request->uri->path;
my $fs = $self->filesys;
if ($request->content) {
@@ -369,13 +367,13 @@
sub propfind {
my($self, $request, $response) = @_;
- my $path = uri_unescape($request->uri->path);
+ my $path = decode_utf8 uri_unescape $request->uri->path;
my $fs = $self->filesys;
my $depth = $request->header('Depth');
my $reqinfo = 'allprop';
my @reqprops;
- if ($request->headers->header('Content-Length')) {
+ if ($request->header('Content-Length')) {
my $content = $request->content;
my $parser = XML::LibXML->new;
my $doc;
@@ -405,7 +403,7 @@
$response->code(207);
$response->message('Multi-Status');
- $response->headers->header('Content-Type' => 'text/xml; charset="utf-8"');
+ $response->header('Content-Type' => 'text/xml; charset="utf-8"');
my $doc = XML::LibXML::Document->new('1.0', 'utf-8');
my $multistat = $doc->createElement('D:multistatus');