Abstract out DataContainer into interface

This commit is contained in:
Garrett Mills 2021-05-22 10:44:52 -05:00
parent 574ddbe9cb
commit 26d54033af
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246

View File

@ -39,11 +39,18 @@ export interface HTTPSourceAddress {
port: number;
}
/**
* Interface describing a container that holds user input data.
*/
export interface DataContainer {
input(key?: string): any
}
/**
* A class that represents an HTTP request from a client.
*/
@Injectable()
export class Request extends ScopedContainer {
export class Request extends ScopedContainer implements DataContainer {
/** The cookie manager for the request. */
public readonly cookies: HTTPCookieJar;
@ -170,7 +177,15 @@ export class Request extends ScopedContainer {
* Get the value of an input field on the request. Spans multiple input sources.
* @param key
*/
public input(key: string) {
public input(key?: string) {
if ( !key ) {
return {
...this.parsedInput,
...this.query,
...this.uploadedFiles,
}
}
if ( key in this.parsedInput ) {
return this.parsedInput[key]
}