Skip to content

Commit

Permalink
send 404 when svg file does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
matyaskopp committed May 28, 2018
1 parent 26bdb20 commit 2235e40
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/PMLTQ/Server/Controller/Svg.pm
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,13 @@ sub result_svg {

if($svg_path){
$self->app->log->debug("Svg path: $svg_path");
unless (-f $svg_path) {
$self->status_error({
code => 404,
message => "File not found"
});
return
}
$self->res->headers->content_type('image/svg+xml');
$self->reply->asset(Mojo::Asset::File->new(path => $svg_path));
} else {
Expand Down
8 changes: 7 additions & 1 deletion t/api_query.t
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,14 @@ $t->post_ok($query_svg_url => json => {
$t->get_ok($svg_url => form => {
nodes => '1281/t-node@t-ln95048-055-p2s3w16'
})->status_is(200)->or(sub { diag p($t->tx->res->json) })
->header_is('Content-Type' => 'image/svg+xml');
->header_is('Content-Type' => 'image/svg+xml')
->content_like('/<title>test cached svg</title>/');


# ask for cached svg that is not in svg directory
$t->get_ok($svg_url => form => {
nodes => '1000/t-node@t-ln94207-33-p2s2w2'
})->status_is(404)->or(sub { diag p($t->tx->res->json) });

# switch to failing print server
$t->app->config->{tree_print_service} = $print_server_url->path('/svg_error')->to_string;
Expand Down

0 comments on commit 2235e40

Please sign in to comment.