Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 5adb1fc

Browse files
committed
Improve compression
1 parent 8107bb3 commit 5adb1fc

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

server/server.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { join } from 'https://deno.land/[email protected]/path/mod.ts'
2+
import { readerFromStreamReader } from "https://deno.land/[email protected]/io/streams.ts"
3+
import { readAll } from "https://deno.land/[email protected]/io/util.ts"
24
import { builtinModuleExts, trimBuiltinModuleExts } from '../framework/core/module.ts'
35
import { resolveURL } from '../framework/core/routing.ts'
46
import { existsFile } from '../shared/fs.ts'
@@ -105,6 +107,8 @@ export class Server {
105107
data = body
106108
} else if (body instanceof ArrayBuffer) {
107109
data = new Uint8Array(body)
110+
} else if (typeof body.getReader === 'function') {
111+
data = await readAll(readerFromStreamReader(body.getReader()))
108112
}
109113
const contentEncoding = compress.accept(acceptEncoding, contentType, data.length)
110114
if (contentEncoding) {
@@ -301,8 +305,8 @@ export class Server {
301305
pathname,
302306
search: Array.from(url.searchParams.keys()).length > 0 ? '?' + url.searchParams.toString() : ''
303307
})
304-
resp.body = html
305308
resp.setHeader('Content-Type', 'text/html; charset=utf-8')
309+
resp.body = html
306310
end(status)
307311
} catch (err) {
308312
try {

0 commit comments

Comments
 (0)