From 77632ad87adfecfa2aa9099d44dcb42ae9a2a208 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 18 Dec 2019 03:36:41 +0000 Subject: viewvcs: flesh out some functionality and test Expose MAX_SIZE via "our" will make it possible to use in tests, and configure, later. Additionally, returning HTTP 500 code for big files is not an Internal Server Error, just a memory limit... Some browsers won't show our HTML response with the link to the raw file in case of errors, either, so we'll return 200 to ensure users can use the link to access the raw blob. Finally, throw in some tests to the existing solver_git testcase, since that was incomplete and was pointlessly loading Plack modules without testing PSGI. --- lib/PublicInbox/ViewVCS.pm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm index 369afe93..842c873c 100644 --- a/lib/PublicInbox/ViewVCS.pm +++ b/lib/PublicInbox/ViewVCS.pm @@ -28,7 +28,7 @@ my $hl = eval { }; my %QP_MAP = ( A => 'oid_a', B => 'oid_b', a => 'path_a', b => 'path_b' ); -my $max_size = 1024 * 1024; # TODO: configurable +our $MAX_SIZE = 1024 * 1024; # TODO: configurable my $BIN_DETECT = 8000; # same as git sub html_page ($$$) { @@ -76,7 +76,7 @@ sub stream_large_blob ($$$$) { sub show_other ($$$$) { my ($ctx, $res, $logref, $fn) = @_; my ($git, $oid, $type, $size) = @$res; - if ($size > $max_size) { + if ($size > $MAX_SIZE) { $$logref = "$oid is too big to show\n" . $$logref; return html_page($ctx, 200, $logref); } @@ -122,11 +122,11 @@ sub solve_result { return show_other($ctx, $res, \$log, $fn) if $type ne 'blob'; my $path = to_filename($di->{path_b} || $hints->{path_b} || 'blob'); my $raw_link = "(raw)"; - if ($size > $max_size) { + if ($size > $MAX_SIZE) { return stream_large_blob($ctx, $res, \$log, $fn) if defined $fn; $log = "
Too big to show, download available\n" .
 			"$oid $type $size bytes $raw_link
" . $log; - return html_page($ctx, 500, \$log); + return html_page($ctx, 200, \$log); } my $blob = $git->cat_file($oid); -- cgit v1.2.3-24-ge0c7