@travetto/web-connect 7.1.4 → 8.0.0-alpha.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.
Files changed (2) hide show
  1. package/package.json +4 -4
  2. package/src/connect.ts +6 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/web-connect",
3
- "version": "7.1.4",
3
+ "version": "8.0.0-alpha.1",
4
4
  "type": "module",
5
5
  "description": "Web integration for Connect-Like Resources",
6
6
  "keywords": [
@@ -25,11 +25,11 @@
25
25
  "directory": "module/web-connect"
26
26
  },
27
27
  "dependencies": {
28
- "@travetto/web": "^7.1.4"
28
+ "@travetto/web": "^8.0.0-alpha.1"
29
29
  },
30
30
  "peerDependencies": {
31
- "@travetto/cli": "^7.1.4",
32
- "@travetto/test": "^7.1.4"
31
+ "@travetto/cli": "^8.0.0-alpha.1",
32
+ "@travetto/test": "^8.0.0-alpha.1"
33
33
  },
34
34
  "peerDependenciesMeta": {
35
35
  "@travetto/test": {
package/src/connect.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { OutgoingHttpHeaders, IncomingMessage, ServerResponse } from 'node:http';
2
2
 
3
- import { castTo } from '@travetto/runtime';
3
+ import { BinaryUtil, castTo, CodecUtil, type BinaryArray } from '@travetto/runtime';
4
4
  import { type WebRequest, WebResponse } from '@travetto/web';
5
5
 
6
6
  export class ConnectRequest implements Pick<IncomingMessage, 'url' | 'headers'> {
@@ -49,7 +49,7 @@ export class ConnectResponse implements Pick<ServerResponse,
49
49
  #response: WebResponse;
50
50
  #headersSent = false;
51
51
  #finished = false;
52
- #written: Buffer[] = [];
52
+ #written: BinaryArray[] = [];
53
53
  #onEndHandlers: (() => void)[] = [];
54
54
 
55
55
  constructor(response?: WebResponse) {
@@ -75,7 +75,7 @@ export class ConnectResponse implements Pick<ServerResponse,
75
75
  writeHead(statusCode: unknown, statusMessage?: unknown, headers?: unknown): this {
76
76
  this.#response.context.httpStatusCode = castTo(statusCode);
77
77
  for (const [key, value] of Object.entries(headers ?? {})) {
78
- this.#response.headers.set(key, value);
78
+ this.#response.headers.set(key, typeof value === 'string' ? value : `${value}`);
79
79
  }
80
80
  this.#headersSent = true;
81
81
  return this;
@@ -123,11 +123,8 @@ export class ConnectResponse implements Pick<ServerResponse,
123
123
  if (this.#headersSent) {
124
124
  this.flushHeaders();
125
125
  }
126
- if (!Buffer.isBuffer(chunk)) {
127
- this.#written.push(Buffer.from(`${chunk}`, castTo(encoding)));
128
- } else {
129
- this.#written.push(chunk);
130
- }
126
+ const chunked = CodecUtil.readChunk(chunk, encoding ? `${encoding}` : undefined);
127
+ this.#written.push(chunked);
131
128
  callback?.();
132
129
  return true;
133
130
  }
@@ -157,7 +154,7 @@ export class ConnectResponse implements Pick<ServerResponse,
157
154
 
158
155
  throwIfSent(): void {
159
156
  if (this.#headersSent) {
160
- this.#response.body = Buffer.concat(this.#written);
157
+ this.#response.body = BinaryUtil.combineBinaryArrays(this.#written);
161
158
  throw this.#response;
162
159
  }
163
160
  }