Skip to content

Commit f847371

Browse files
committed
Setter content-length (estimat) for pdf-batches
1 parent 891ee65 commit f847371

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

server/src/pdf/PdfGenerator.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ type PdfResult = {
1414
filename: string;
1515
};
1616

17-
type ZipResult = {
18-
dataStream: NodeJS.ReadableStream;
19-
filename: string;
20-
};
21-
2217
type ConstructorProps = {
2318
browser: Browser;
2419
contentService: CmsArchiveContentService;
@@ -52,10 +47,9 @@ export class PdfGenerator {
5247

5348
const zipFilename = `${newestVersion.name}_${newestVersion.meta.timestamp}-${oldestVersion.meta.timestamp}.zip`;
5449

55-
res.setHeader('Content-Disposition', `attachment; filename="${zipFilename}"`).setHeader(
56-
'Content-Type',
57-
mime.lookup(zipFilename) || 'application/octet-stream'
58-
);
50+
res.setHeader('Content-Disposition', `attachment; filename="${zipFilename}"`)
51+
.setHeader('Content-Type', mime.lookup(zipFilename) || 'application/octet-stream')
52+
.setHeader('Transfer-Encoding', 'chunked');
5953

6054
const archive = archiver('zip');
6155

@@ -77,6 +71,12 @@ export class PdfGenerator {
7771
return;
7872
}
7973

74+
if (!res.headersSent) {
75+
// Set an estimate for content-length, which allows clients to track the download progress
76+
// This header is not according to spec for chunked responses, but browsers seem to respect it
77+
res.setHeader('Content-Length', pdf.length * contentVersions.length);
78+
}
79+
8080
const fileName = this.getPdfFilename(content);
8181

8282
archive.append(pdf, { name: fileName });

0 commit comments

Comments
 (0)