Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(server): gzip large thread snapshots #4788

Mergedt3dotgg(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/4788/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

Showing 4 changed files with 154 additions and 2 deletions (loading 1).

x
0 of 4 viewed, 4 left
53 additions and 2 deletionsapps/server/src/http.test.tsModified
View file
@@ -1,6 +1,11 @@
-import { describe, expect, it } from "vite-plus/test";
+import { expect, it } from "@effect/vitest";
+import * as NodeZlib from "node:zlib";
+import * as Effect from "effect/Effect";
+import * as Stream from "effect/Stream";
+import { HttpServerResponse } from "effect/unstable/http";
+import { describe } from "vite-plus/test";
​
-import { isLoopbackHostname, resolveDevRedirectUrl } from "./http.ts";
+import { compressHttpResponse, isLoopbackHostname, resolveDevRedirectUrl } from "./http.ts";
​
describe("http dev routing", () => {
it("treats localhost and loopback addresses as local", () => {
@@ -25,3 +30,49 @@
);
});
});
+​
+describe("http compression", () => {
+ it.effect("gzips large JSON responses when the client accepts it", () =>
+ Effect.gen(function* () {
+ const body = `{"value":"${"compressible".repeat(1_000)}"}`;
+ const response = compressHttpResponse(
+ HttpServerResponse.text(body, { contentType: "application/json" }),
+ "br, gzip, deflate",
+ );
+​
+ expect(response.headers["content-encoding"]).toBe("gzip");
+ expect(response.headers["content-length"]).toBeUndefined();