Skip to content

Commit

Permalink
small optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Aug 6, 2014
1 parent 5966b12 commit 1dae377
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/Mojolicious/Static.pm
Expand Up @@ -60,14 +60,11 @@ sub is_fresh {

# If-None-Match
my $res_headers = $c->res->headers;
my $matches = $match && ($res_headers->etag // '') ne $match ? 0 : 1;
return undef if $match && ($res_headers->etag // '') ne $match;

# If-Modified-Since
return $matches unless (my $last = $res_headers->last_modified) && $since;
my $unmodified
= Mojo::Date->new($last)->epoch <= (Mojo::Date->new($since)->epoch // 0);

return $matches && $unmodified;
return !!$match unless (my $last = $res_headers->last_modified) && $since;
return _epoch($last) <= (_epoch($since) // 0);
}

sub serve {
Expand Down Expand Up @@ -108,6 +105,8 @@ sub serve_asset {
return $res->content->asset($asset->start_range($start)->end_range($end));
}

sub _epoch { Mojo::Date->new(shift)->epoch }

sub _get_data_file {
my ($self, $rel) = @_;

Expand Down

0 comments on commit 1dae377

Please sign in to comment.