about summary refs log tree commit homepage
path: root/lib/PublicInbox/ViewVCS.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-12-18 03:36:41 +0000
committerEric Wong <e@80x24.org>2019-12-18 23:26:29 +0000
commit77632ad87adfecfa2aa9099d44dcb42ae9a2a208 (patch)
treef638713cc2323ebc0d1c24695fafeeca9c5fc213 /lib/PublicInbox/ViewVCS.pm
parent9342aad429aa437b743c75bd18e06e3df25a3b6a (diff)
downloadpublic-inbox-77632ad87adfecfa2aa9099d44dcb42ae9a2a208.tar.gz
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.
Diffstat (limited to 'lib/PublicInbox/ViewVCS.pm')
-rw-r--r--lib/PublicInbox/ViewVCS.pm8
1 files changed, 4 insertions, 4 deletions
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 = "(<a\nhref=$path>raw</a>)";
-        if ($size > $max_size) {
+        if ($size > $MAX_SIZE) {
                 return stream_large_blob($ctx, $res, \$log, $fn) if defined $fn;
                 $log = "<pre><b>Too big to show, download available</b>\n" .
                         "$oid $type $size bytes $raw_link</pre>" . $log;
-                return html_page($ctx, 500, \$log);
+                return html_page($ctx, 200, \$log);
         }
 
         my $blob = $git->cat_file($oid);