You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
932 B

import AppClass from '../../lifecycle/AppClass.ts'
import {Request} from '../Request.ts'
import {HTTPStatus} from '../../const/http.ts'
/**
* A base class that renders a response to a request.
* @extends AppClass
*/
export default abstract class ResponseFactory extends AppClass {
/**
* The HTTP status to set on the response.
* @type HTTPStatus
*/
protected target_status: HTTPStatus = HTTPStatus.OK
/**
* Write the value to the response.
* @param {Request} request
* @return Promise<Request>
*/
public async write(request: Request): Promise<Request> {
request.response.status = this.target_status
return request
}
/**
* Override the response status.
* @param {HTTPStatus} status
* @return ResponseFactory
*/
public status(status: HTTPStatus): ResponseFactory {
this.target_status = status
return this
}
}