diff --git a/package.json b/package.json index a08e46b..8d1ff62 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/http/response/StringResponseFactory.ts b/src/http/response/StringResponseFactory.ts index 84dd61c..2f103bb 100644 --- a/src/http/response/StringResponseFactory.ts +++ b/src/http/response/StringResponseFactory.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 = 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 + } }