Subject: | Data in response truncated if longer than 32KB |
Date: | Thu, 22 Oct 2020 16:16:54 +1100 |
To: | <bug-CGI-Emulate-PSGI-Streaming [...] rt.cpan.org> |
From: | <dcook [...] prosentient.com.au> |
I'm working on a PSGI application, and CGI::Emulate::PSGI::Streaming looked
like exactly what I needed.
However, I notice in CGI::Parse::PSGI::Streaming::Handle that the data is
being truncated from 33750 to 32768 characters at this point:
https://metacpan.org/source/CGI::Parse::PSGI::Streaming::Handle#L41.
The $buf variables contains the 33750 characters (HTTP headers and body),
but after 'print {$self->{fh}} substr($buf, $offset, $len);', you can see
that $self->{buffer} only contains 32768 characters. This leads to an
incomplete response being sent to the browser. This is happening on Debian 9
Stretch (Perl v5.24.1) using CGI-Emulate-PSGI-Streaming-1.0.0.
I'm surprised by the 32KB limit, and I actually can't reproduce the problem
when I write my own programs from scratch using a similar
$self->{fh}/$self->{buffer} setup.
Using Devel::Peek, I see that my string in $buf has the UTF8 flag, while
$self->{buffer} does not. My $buf had CUR = 33750 and LEN = 33752, whereas
$self->{buffer} has a massive discrepancy where CUR = 32768 but LEN is
34576.
I'm out of ideas at this point though. I like the idea of
CGI::Emulate::PSGI::Streaming, since CGI::Emulate::PSGI isn't practical for
many use cases, but I can't use this as it stands, unfortunately.
David Cook
Software Engineer
Prosentient Systems
72/330 Wattle St
Ultimo, NSW 2007
Australia
Office: 02 9212 0899
Online: 02 8005 0595