support content-length

This commit is contained in:
Jephté Clain 2025-06-23 18:20:40 +04:00
parent ce337ce3bc
commit 5dc2d3d019
2 changed files with 7 additions and 1 deletions

View File

@ -26,7 +26,7 @@ class CsvBuilder extends AbstractBuilder {
} }
protected function _checkOk(): bool { protected function _checkOk(): bool {
$size = $this->ftell(); $this->size = $size = $this->ftell();
if ($size === 0) return false; if ($size === 0) return false;
$this->rewind(); $this->rewind();
return true; return true;

View File

@ -131,6 +131,8 @@ abstract class AbstractBuilder extends TempStream implements IBuilder {
protected bool $built = false, $closed = false; protected bool $built = false, $closed = false;
protected ?int $size = null;
function build(?iterable $rows=null, bool $close=true): bool { function build(?iterable $rows=null, bool $close=true): bool {
$ok = true; $ok = true;
if (!$this->built) { if (!$this->built) {
@ -155,6 +157,10 @@ abstract class AbstractBuilder extends TempStream implements IBuilder {
if ($output !== null) { if ($output !== null) {
http::download_as(path::filename($output)); http::download_as(path::filename($output));
} }
$size = $this->size;
if ($size !== null) {
header("Content-Length: $size");
}
$this->sentHeaders = true; $this->sentHeaders = true;
} }