Abstract out DataContainer into interface
This commit is contained in:
parent
574ddbe9cb
commit
26d54033af
@ -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]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user