20 lines
574 B
TypeScript
20 lines
574 B
TypeScript
|
import {ResponseFactory} from "./ResponseFactory";
|
||
|
import {Request} from "../lifecycle/Request";
|
||
|
|
||
|
export function plaintext(value: string): StringResponseFactory {
|
||
|
return new StringResponseFactory(value)
|
||
|
}
|
||
|
|
||
|
export class StringResponseFactory extends ResponseFactory {
|
||
|
constructor(
|
||
|
public readonly value: string,
|
||
|
) { super() }
|
||
|
|
||
|
public async write(request: Request) {
|
||
|
request = await super.write(request)
|
||
|
request.response.setHeader('Content-Type', 'text/plain')
|
||
|
request.response.body = this.value
|
||
|
return request
|
||
|
}
|
||
|
}
|