mirror of
https://github.com/anomalyco/opencode.git
synced 2026-02-01 22:48:16 +00:00
perf(server): gzip compress session messages response
Large sessions can have 20MB+ JSON payloads which take 20-30s to transfer over mobile networks. Gzip compression reduces this to ~2-3MB, improving mobile load times by ~5x.
This commit is contained in:
@@ -579,6 +579,17 @@ export const SessionRoutes = lazy(() =>
|
||||
sessionID: c.req.valid("param").sessionID,
|
||||
limit: query.limit,
|
||||
})
|
||||
const acceptEncoding = c.req.header("accept-encoding") ?? ""
|
||||
if (acceptEncoding.includes("gzip")) {
|
||||
const json = JSON.stringify(messages)
|
||||
const compressed = Bun.gzipSync(json)
|
||||
return new Response(compressed, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Content-Encoding": "gzip",
|
||||
},
|
||||
})
|
||||
}
|
||||
return c.json(messages)
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user