Perl: creating input and error streams if closed.

Application handler can do anything with a stream object (including close it).
Once the stream is closed, Unit creates a new stream.

This closes #616 issue on GitHub.
This commit is contained in:
Max Romanov
2021-12-27 16:37:35 +03:00
parent 6507849282
commit f845283820
7 changed files with 167 additions and 168 deletions

View File

@@ -0,0 +1,17 @@
use FileHandle;
my $app = sub {
my ($environ) = @_;
$environ->{'psgi.input'}->read(my $body, 1024);
open my $io, "<", \$body;
# This makes $io work as FileHandle under 5.8, .10 and .11.
bless $io, 'FileHandle';
$environ->{'psgix.input.buffered'} = 1;
$environ->{'psgi.input'} = $io;
return ['200', ['Content-Length' => length $body], [$body]];
};

View File

@@ -0,0 +1,8 @@
my $app = sub {
my ($environ) = @_;
$environ->{'psgi.input'}->read(my $body, 1024);
$environ->{'psgi.input'}->close();
return ['200', ['Content-Length' => length $body], [$body]];
};

View File

@@ -100,6 +100,28 @@ class TestPerlApplication(TestApplicationPerl):
self.post(body='0123456789')['body'] == '0123456789'
), 'input read parts'
def test_perl_application_input_buffered_read(self):
self.load('input_buffered_read')
assert (
self.post(body='012345')['body'] == '012345'
), 'buffered read #1'
assert (
self.post(body='9876543210')['body'] == '9876543210'
), 'buffered read #2'
def test_perl_application_input_close(self):
self.load('input_close')
assert (
self.post(body='012345')['body'] == '012345'
), 'input close #1'
assert (
self.post(body='9876543210')['body'] == '9876543210'
), 'input close #2'
@pytest.mark.skip('not yet')
def test_perl_application_input_read_offset(self):
self.load('input_read_offset')