|
|
@ -100,6 +100,7 @@ export class Response {
|
|
|
|
|
|
|
|
|
|
|
|
/** Set the value of the response header. */
|
|
|
|
/** Set the value of the response header. */
|
|
|
|
public setHeader(name: string, value: string | string[]): this {
|
|
|
|
public setHeader(name: string, value: string | string[]): this {
|
|
|
|
|
|
|
|
this.logging.verbose(`Will set header on response: ${name}`)
|
|
|
|
if ( this.sentHeaders ) {
|
|
|
|
if ( this.sentHeaders ) {
|
|
|
|
throw new HeadersAlreadySentError(this, name)
|
|
|
|
throw new HeadersAlreadySentError(this, name)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -113,6 +114,7 @@ export class Response {
|
|
|
|
* @param data
|
|
|
|
* @param data
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public setHeaders(data: {[name: string]: string | string[]}): this {
|
|
|
|
public setHeaders(data: {[name: string]: string | string[]}): this {
|
|
|
|
|
|
|
|
this.logging.verbose(`Will set headers on response: ${Object.keys(data).join(', ')}`)
|
|
|
|
if ( this.sentHeaders ) {
|
|
|
|
if ( this.sentHeaders ) {
|
|
|
|
throw new HeadersAlreadySentError(this)
|
|
|
|
throw new HeadersAlreadySentError(this)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -128,12 +130,16 @@ export class Response {
|
|
|
|
* @param value
|
|
|
|
* @param value
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public appendHeader(name: string, value: string | string[]): this {
|
|
|
|
public appendHeader(name: string, value: string | string[]): this {
|
|
|
|
|
|
|
|
this.logging.verbose(`Will append header: ${name}`)
|
|
|
|
|
|
|
|
|
|
|
|
if ( this.sentHeaders ) {
|
|
|
|
if ( this.sentHeaders ) {
|
|
|
|
throw new HeadersAlreadySentError(this, name)
|
|
|
|
throw new HeadersAlreadySentError(this, name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( !Array.isArray(value) ) {
|
|
|
|
if ( !Array.isArray(value) ) {
|
|
|
|
value = [value]
|
|
|
|
value = [value]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let existing = this.headers[name] ?? []
|
|
|
|
let existing = this.headers[name] ?? []
|
|
|
|
if ( !Array.isArray(existing) ) {
|
|
|
|
if ( !Array.isArray(existing) ) {
|
|
|
|
existing = [existing]
|
|
|
|
existing = [existing]
|
|
|
@ -152,6 +158,7 @@ export class Response {
|
|
|
|
* Write the headers to the client.
|
|
|
|
* Write the headers to the client.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public sendHeaders(): this {
|
|
|
|
public sendHeaders(): this {
|
|
|
|
|
|
|
|
this.logging.verbose(`Sending headers...`)
|
|
|
|
const headers = {} as any
|
|
|
|
const headers = {} as any
|
|
|
|
|
|
|
|
|
|
|
|
const setCookieHeaders = this.cookies.getSetCookieHeaders()
|
|
|
|
const setCookieHeaders = this.cookies.getSetCookieHeaders()
|
|
|
@ -199,6 +206,7 @@ export class Response {
|
|
|
|
* @param data
|
|
|
|
* @param data
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public async write(data: string | Buffer | Uint8Array | Readable): Promise<void> {
|
|
|
|
public async write(data: string | Buffer | Uint8Array | Readable): Promise<void> {
|
|
|
|
|
|
|
|
this.logging.verbose(`Writing headers & data to response... (destroyed? ${this.serverResponse.destroyed})`)
|
|
|
|
return new Promise<void>((res, rej) => {
|
|
|
|
return new Promise<void>((res, rej) => {
|
|
|
|
if ( this.responseEnded || this.serverResponse.destroyed ) {
|
|
|
|
if ( this.responseEnded || this.serverResponse.destroyed ) {
|
|
|
|
throw new ErrorWithContext('Tried to write to Response after lifecycle ended.')
|
|
|
|
throw new ErrorWithContext('Tried to write to Response after lifecycle ended.')
|
|
|
|