File tree Expand file tree Collapse file tree 3 files changed +11
-6
lines changed
Expand file tree Collapse file tree 3 files changed +11
-6
lines changed Original file line number Diff line number Diff 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 ( ) ;
Original file line number Diff line number Diff 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 ) ;
Original file line number Diff line number Diff 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 ) ;
You can’t perform that action at this time.
0 commit comments