@syncular/server-hono 0.29.0 → 0.29.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -93,6 +93,7 @@ export function createSyncularHono(options) {
93
93
  ? { 'Content-Encoding': encoded.contentEncoding }
94
94
  : { 'Content-Length': String(result.byteLength) }),
95
95
  },
96
+ ...ALREADY_ENCODED,
96
97
  });
97
98
  }
98
99
  // §5.8 shipped default: compress the body per Accept-Encoding
@@ -101,11 +102,15 @@ export function createSyncularHono(options) {
101
102
  // decodes transparently on the client.
102
103
  const bytes = new Uint8Array(await new Response(result.body).arrayBuffer());
103
104
  const encoded = encodeSegmentBody(bytes, acceptEncoding);
104
- return c.body(encoded.bytes.slice().buffer, 200, {
105
- ...result.headers,
106
- ...(encoded.contentEncoding !== undefined
107
- ? { 'Content-Encoding': encoded.contentEncoding }
108
- : {}),
105
+ return new Response(encoded.bytes.slice().buffer, {
106
+ status: 200,
107
+ headers: {
108
+ ...result.headers,
109
+ ...(encoded.contentEncoding !== undefined
110
+ ? { 'Content-Encoding': encoded.contentEncoding }
111
+ : {}),
112
+ },
113
+ ...ALREADY_ENCODED,
109
114
  });
110
115
  }
111
116
  catch (error) {
@@ -180,3 +185,13 @@ export function createSyncularHono(options) {
180
185
  });
181
186
  return app;
182
187
  }
188
+ /**
189
+ * The segment route encodes its own body (§5.8) and declares
190
+ * `Content-Encoding`. workerd encodes every response that declares one again
191
+ * unless `encodeBody: 'manual'` marks the body as encoded, so a Workers client
192
+ * would decode gzip inside gzip and fail §5.1 verification
193
+ * (SYNCULAR-WORKERS-SEGMENT-ENCODING-001). Other runtimes ignore the member.
194
+ */
195
+ const ALREADY_ENCODED = {
196
+ encodeBody: 'manual',
197
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syncular/server-hono",
3
- "version": "0.29.0",
3
+ "version": "0.29.1",
4
4
  "description": "Hono adapter for the Syncular sync server",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Benjamin Kniffler",
@@ -45,10 +45,10 @@
45
45
  "!dist/**/*.test.d.ts"
46
46
  ],
47
47
  "dependencies": {
48
- "@syncular/server": "0.29.0",
48
+ "@syncular/server": "0.29.1",
49
49
  "hono": "^4.13.7"
50
50
  },
51
51
  "devDependencies": {
52
- "@syncular/core": "0.29.0"
52
+ "@syncular/core": "0.29.1"
53
53
  }
54
54
  }
package/src/index.ts CHANGED
@@ -143,6 +143,7 @@ export function createSyncularHono(options: SyncularHonoOptions): Hono {
143
143
  ? { 'Content-Encoding': encoded.contentEncoding }
144
144
  : { 'Content-Length': String(result.byteLength) }),
145
145
  },
146
+ ...ALREADY_ENCODED,
146
147
  });
147
148
  }
148
149
  // §5.8 shipped default: compress the body per Accept-Encoding
@@ -153,11 +154,15 @@ export function createSyncularHono(options: SyncularHonoOptions): Hono {
153
154
  await new Response(result.body).arrayBuffer(),
154
155
  );
155
156
  const encoded = encodeSegmentBody(bytes, acceptEncoding);
156
- return c.body(encoded.bytes.slice().buffer as ArrayBuffer, 200, {
157
- ...result.headers,
158
- ...(encoded.contentEncoding !== undefined
159
- ? { 'Content-Encoding': encoded.contentEncoding }
160
- : {}),
157
+ return new Response(encoded.bytes.slice().buffer as ArrayBuffer, {
158
+ status: 200,
159
+ headers: {
160
+ ...result.headers,
161
+ ...(encoded.contentEncoding !== undefined
162
+ ? { 'Content-Encoding': encoded.contentEncoding }
163
+ : {}),
164
+ },
165
+ ...ALREADY_ENCODED,
161
166
  });
162
167
  } catch (error) {
163
168
  return errorResponse(error, 'segments');
@@ -247,3 +252,13 @@ export function createSyncularHono(options: SyncularHonoOptions): Hono {
247
252
 
248
253
  return app;
249
254
  }
255
+ /**
256
+ * The segment route encodes its own body (§5.8) and declares
257
+ * `Content-Encoding`. workerd encodes every response that declares one again
258
+ * unless `encodeBody: 'manual'` marks the body as encoded, so a Workers client
259
+ * would decode gzip inside gzip and fail §5.1 verification
260
+ * (SYNCULAR-WORKERS-SEGMENT-ENCODING-001). Other runtimes ignore the member.
261
+ */
262
+ const ALREADY_ENCODED: { readonly encodeBody: 'manual' } = {
263
+ encodeBody: 'manual',
264
+ };