forked from plack/Plack
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use TempBuffer in Dechunk middleware.
TempBuffer now added Auto backend, which begins with PerlIO but switches to File when the size exceeds the max limit, which may have a little overhead but suitable for chunked requests.
- Loading branch information
Showing
6 changed files
with
90 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package Plack::TempBuffer::Auto; | ||
use strict; | ||
use parent 'Plack::TempBuffer'; | ||
|
||
sub new { | ||
my($class, undef, $max_memory_size) = @_; | ||
bless { | ||
_buffer => Plack::TempBuffer->create('PerlIO'), | ||
_max => $max_memory_size, | ||
}, $class; | ||
} | ||
|
||
sub print { | ||
my $self = shift; | ||
$self->{_buffer}->print(@_); | ||
|
||
if ($self->{_buffer}->size > $self->{_max}) { | ||
my $buf = $self->{_buffer}->{buffer}; | ||
$self->{_buffer} = Plack::TempBuffer->create('File'), | ||
$self->{_buffer}->print($buf); | ||
} | ||
} | ||
|
||
sub size { | ||
my $self = shift; | ||
$self->{_buffer}->size; | ||
} | ||
|
||
sub rewind { | ||
my $self = shift; | ||
$self->{_buffer}->rewind; | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters