Skip to content

Commit 42ded80

Browse files
committed
Clarify and fix use of @internal Request response headers
1 parent 28ac28e commit 42ded80

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/Request.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,9 @@ export class Request<A> {
261261
}
262262

263263
/**
264-
* Response headers that the Response to this request should include.
264+
* Set in advance response headers that the Response to this request should include. Do not use if a Response
265+
* context is available (use {@link Response#headers} instead). Responses cannot see these headers and may overwrite
266+
* them if there is a collision.
265267
* @internal
266268
*/
267269
public _responseHeaders = new Headers();

src/response/BufferResponse.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ export abstract class BufferResponse<A> extends Response<A> {
1414
protected override async send(res: http.ServerResponse, req?: Request<A>): Promise<void> {
1515
const buffer = await this.readBuffer();
1616
if (req !== undefined) {
17-
if (res.chunkedEncoding)
18-
req._responseHeaders.set("transfer-encoding", "chunked");
19-
else
20-
req._responseHeaders.set("content-length", buffer.byteLength.toString());
17+
if (res.chunkedEncoding) {
18+
if (!this.headers.has("transfer-encoding"))
19+
this.headers.set("transfer-encoding", "chunked");
20+
}
21+
else if (!this.headers.has("content-length"))
22+
this.headers.set("content-length", buffer.byteLength.toString());
2123
}
2224
this.writeHead(res, req);
2325
res.end(buffer);

src/response/Response.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ export abstract class Response<A> {
6767
}
6868

6969
/**
70-
* Set the HTTP response status code and headers.
70+
* Set and send the HTTP response status code and headers. No more headers can be sent after this.
71+
* @final
7172
*/
7273
protected writeHead(res: http.ServerResponse, req?: Request<A>) {
7374
const headers = this.allHeaders(res, req);

0 commit comments

Comments
 (0)