lib/src/http/response/ResponseFactory.ts

27 lines
772 B
TypeScript
Raw Normal View History

2021-06-03 03:36:25 +00:00
import {HTTPStatus} from '../../util'
import {Request} from '../lifecycle/Request'
2021-03-25 13:50:13 +00:00
/**
* Abstract class that defines "factory" that knows how to write a particular
* response to the response object.
*/
export abstract class ResponseFactory {
2021-03-25 13:50:13 +00:00
/** The status that should be set on the response. */
protected targetStatus: HTTPStatus = HTTPStatus.OK
2021-03-25 13:50:13 +00:00
/**
* Called to write the response data to the HTTP response object.
* @param request
*/
public async write(request: Request): Promise<Request> {
request.response.setStatus(this.targetStatus)
return request
}
2021-03-25 13:50:13 +00:00
/** Set the target status of this factory. */
2021-06-03 03:36:25 +00:00
public status(status: HTTPStatus): this {
this.targetStatus = status
return this
}
}