Commit 1d4dc6a0 authored by Dietmar Maurer's avatar Dietmar Maurer

pveproxy: implement if-modified-since

parent 81af3133
...@@ -157,7 +157,7 @@ sub response { ...@@ -157,7 +157,7 @@ sub response {
$content = ""; $content = "";
} }
$reqstate->{keep_alive} = 0 if ($code >= 300) || $self->{end_loop}; $reqstate->{keep_alive} = 0 if ($code >= 400) || $self->{end_loop};
$reqstate->{log}->{code} = $code; $reqstate->{log}->{code} = $code;
...@@ -230,11 +230,24 @@ sub send_file_start { ...@@ -230,11 +230,24 @@ sub send_file_start {
# Note: aio_load() this is not really async unless we use IO::AIO! # Note: aio_load() this is not really async unless we use IO::AIO!
eval { eval {
my $r = $reqstate->{request};
my $fh = IO::File->new($filename, '<') || my $fh = IO::File->new($filename, '<') ||
die "$!\n"; die "$!\n";
my $stat = File::stat::stat($fh) || my $stat = File::stat::stat($fh) ||
die "$!\n"; die "$!\n";
my $mtime = $stat->mtime;
if (my $ifmod = $r->header('if-modified-since')) {
my $iftime = HTTP::Date::str2time($ifmod);
if ($mtime <= $iftime) {
my $resp = HTTP::Response->new(304, "NOT MODIFIED");
$self->response($reqstate, $resp, $mtime);
return;
}
}
my $data; my $data;
my $len = sysread($fh, $data, $stat->size); my $len = sysread($fh, $data, $stat->size);
die "got short file\n" if !defined($len) || $len != $stat->size; die "got short file\n" if !defined($len) || $len != $stat->size;
...@@ -256,7 +269,7 @@ sub send_file_start { ...@@ -256,7 +269,7 @@ sub send_file_start {
my $header = HTTP::Headers->new(Content_Type => $ct); my $header = HTTP::Headers->new(Content_Type => $ct);
my $resp = HTTP::Response->new(200, "OK", $header, $data); my $resp = HTTP::Response->new(200, "OK", $header, $data);
$self->response($reqstate, $resp, $stat->mtime); $self->response($reqstate, $resp, $mtime);
}; };
if (my $err = $@) { if (my $err = $@) {
$self->error($reqstate, 501, $err); $self->error($reqstate, 501, $err);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment