Allow overriding content-type of plaintext response factory

master
Garrett Mills 2 years ago
parent 771fed8002
commit c7557cf5b6

@ -1,6 +1,6 @@
{
"name": "@extollo/lib",
"version": "0.9.28",
"version": "0.9.29",
"description": "The framework library that lifts up your code.",
"main": "lib/index.js",
"types": "lib/index.d.ts",

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

Loading…
Cancel
Save