From 5dc2d3d01959c8ae13befe6f5484598f5de0faca Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Mon, 23 Jun 2025 18:20:40 +0400 Subject: [PATCH] support content-length --- php/src/file/csv/CsvBuilder.php | 2 +- php/src/file/tab/AbstractBuilder.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/php/src/file/csv/CsvBuilder.php b/php/src/file/csv/CsvBuilder.php index 24899b9..ef30d2c 100644 --- a/php/src/file/csv/CsvBuilder.php +++ b/php/src/file/csv/CsvBuilder.php @@ -26,7 +26,7 @@ class CsvBuilder extends AbstractBuilder { } protected function _checkOk(): bool { - $size = $this->ftell(); + $this->size = $size = $this->ftell(); if ($size === 0) return false; $this->rewind(); return true; diff --git a/php/src/file/tab/AbstractBuilder.php b/php/src/file/tab/AbstractBuilder.php index 45c1cd9..4514442 100644 --- a/php/src/file/tab/AbstractBuilder.php +++ b/php/src/file/tab/AbstractBuilder.php @@ -131,6 +131,8 @@ abstract class AbstractBuilder extends TempStream implements IBuilder { protected bool $built = false, $closed = false; + protected ?int $size = null; + function build(?iterable $rows=null, bool $close=true): bool { $ok = true; if (!$this->built) { @@ -155,6 +157,10 @@ abstract class AbstractBuilder extends TempStream implements IBuilder { if ($output !== null) { http::download_as(path::filename($output)); } + $size = $this->size; + if ($size !== null) { + header("Content-Length: $size"); + } $this->sentHeaders = true; }