import {HTTPResponse} from './type/HTTPResponse.ts' import {HTTPRequest} from './type/HTTPRequest.ts' import {ServerRequest} from '../external/http.ts' import {file_server} from '../external/std.ts' import {CookieJar} from './CookieJar.ts' /** * Base class for a Daton-managed response. * @implements HTTPResponse */ export class Response implements HTTPResponse { /** * The outgoing HTTP status. * @type HTTPStatus */ public status = 200 /** * The response headers. * @type Headers */ public headers = new Headers() /** * The response body. * @type string */ public body = '' /** * The cookie manager. * @type CookieJar */ public readonly cookies: CookieJar /** * The raw Deno request * @type ServerRequest */ private readonly _deno_req: ServerRequest /** * The associated Daton request. * @type HTTPRequest */ private readonly _request: HTTPRequest /** * True if the response has been sent. * @type boolean */ private _sent = false /** * True if the response has been send. * @type boolean */ get sent() { return this._sent } /** * Create a new response * @param {HTTPRequest} to - the associated request */ constructor(to: HTTPRequest) { this._deno_req = to.to_native this._request = to this.cookies = new CookieJar(to) } /** * Send the response. */ send() { this._sent = true return this._deno_req.respond(this) } }