Improve file upload speed

This commit is contained in:
Allan Kristensen 2014-02-26 15:26:37 +01:00
parent 4f2465c6c5
commit 2dc8f8bdc8

View File

@ -511,7 +511,7 @@ and store it in the global %in hash. The optional parameters are :
sub ReadParseMime sub ReadParseMime
{ {
my ($max, $cbfunc, $cbargs) = @_; my ($max, $cbfunc, $cbargs) = @_;
my ($boundary, $line, $foo, $name, $got, $file); my ($boundary, $line, $foo, $name, $got, $file, $count_lines, $max_lines);
my $err = &text('readparse_max', $max); my $err = &text('readparse_max', $max);
$ENV{'CONTENT_TYPE'} =~ /boundary=(.*)$/ || &error($text{'readparse_enc'}); $ENV{'CONTENT_TYPE'} =~ /boundary=(.*)$/ || &error($text{'readparse_enc'});
if ($ENV{'CONTENT_LENGTH'} && $max && $ENV{'CONTENT_LENGTH'} > $max) { if ($ENV{'CONTENT_LENGTH'} && $max && $ENV{'CONTENT_LENGTH'} > $max) {
@ -519,6 +519,8 @@ if ($ENV{'CONTENT_LENGTH'} && $max && $ENV{'CONTENT_LENGTH'} > $max) {
} }
&$cbfunc(0, $ENV{'CONTENT_LENGTH'}, $file, @$cbargs) if ($cbfunc); &$cbfunc(0, $ENV{'CONTENT_LENGTH'}, $file, @$cbargs) if ($cbfunc);
$boundary = $1; $boundary = $1;
$count_lines = 0;
$max_lines = 1000;
<STDIN>; # skip first boundary <STDIN>; # skip first boundary
while(1) { while(1) {
$name = ""; $name = "";
@ -569,8 +571,12 @@ while(1) {
while(1) { while(1) {
$line = <STDIN>; $line = <STDIN>;
$got += length($line); $got += length($line);
$count_lines++;
if ($count_lines == $max_lines) {
&$cbfunc($got, $ENV{'CONTENT_LENGTH'}, $file, @$cbargs) &$cbfunc($got, $ENV{'CONTENT_LENGTH'}, $file, @$cbargs)
if ($cbfunc); if ($cbfunc);
$count_lines = 0;
}
if ($max && $got > $max) { if ($max && $got > $max) {
#print STDERR "over limit of $max\n"; #print STDERR "over limit of $max\n";
#&error($err); #&error($err);
@ -581,8 +587,6 @@ while(1) {
if ($cbfunc); if ($cbfunc);
return; return;
} }
my $ptline = $line;
$ptline =~ s/[^a-zA-Z0-9\-]/\./g;
if (index($line, $boundary) != -1) { last; } if (index($line, $boundary) != -1) { last; }
$in{$name} .= $line; $in{$name} .= $line;
} }