Asterbing said:
Because when CONTENT_LENGTH has been informed by server itself after
receiving of entire POST, I can effectively read STDIN, extract uploaded
data and do the substraction.
Once you've extracted the data, why would you need to do the subtraction?
Once you've extracted the data, you already have the data, just ask the
data how big it is. I thought the whole point was to avoid extracting the
data in the first place.
But, when CONTENT_LENGTH comes from original request, how to proceed ?
Say, I wish to avoid any upload (I mean write on server, since data may
already be in STDIN) above 1MB, how to proceed ?
You have enough memory to load a 1 MB of non-file-upload form-data into
memory, but not enough disk to temporarily save 1 MB of file-upload data?
That just doesn't make sense. If you computer will break with 1MB of
posted data, don't allow that size of post, whether it is file upload or
not. If your computer won't break, then what's the problem? Uploaded it,
ask how big each form-part is, and do the appropriate thing.
Having said that, you could hack/subclass the read_multipart method
of CGI.pm to have it, at a certain size, stop copying the data into the
file, something like:
while (defined($data = $buffer->read)) {
if (defined $self->{'.upload_hook'})
{
$totalbytes += length($data);
&{$self->{'.upload_hook'}}($filename ,$data, $totalbytes,
$self->{'.upload_data'});
}
##print $filehandle $data;
print $filehandle $data unless $totalbytes > $FOO::Asterbing_size;
}
Of course, you would have to set a flag or something so that you know that
this has happened.
Xho