|
|
@ -13,6 +13,8 @@ export function plaintext(value: string): StringResponseFactory {
|
|
|
|
* Response factory that renders a given string as the response in plaintext.
|
|
|
|
* Response factory that renders a given string as the response in plaintext.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
export class StringResponseFactory extends ResponseFactory {
|
|
|
|
export class StringResponseFactory extends ResponseFactory {
|
|
|
|
|
|
|
|
protected targetContentType = 'text/plain'
|
|
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
constructor(
|
|
|
|
/** The string to write as the body. */
|
|
|
|
/** The string to write as the body. */
|
|
|
|
public readonly value: string,
|
|
|
|
public readonly value: string,
|
|
|
@ -22,8 +24,14 @@ export class StringResponseFactory extends ResponseFactory {
|
|
|
|
|
|
|
|
|
|
|
|
public async write(request: Request): Promise<Request> {
|
|
|
|
public async write(request: Request): Promise<Request> {
|
|
|
|
request = await super.write(request)
|
|
|
|
request = await super.write(request)
|
|
|
|
request.response.setHeader('Content-Type', 'text/plain')
|
|
|
|
request.response.setHeader('Content-Type', this.targetContentType)
|
|
|
|
request.response.body = this.value
|
|
|
|
request.response.body = this.value
|
|
|
|
return request
|
|
|
|
return request
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Override the content type of the string. */
|
|
|
|
|
|
|
|
public contentType(type: string): this {
|
|
|
|
|
|
|
|
this.targetContentType = type
|
|
|
|
|
|
|
|
return this
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|