enhancement(extollo/extollo#2): add kernel module for parsing request body contents, uploading files
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import {Injectable, ScopedContainer, Container} from "@extollo/di"
|
||||
import {infer} from "@extollo/util"
|
||||
import {infer, UniversalPath} from "@extollo/util"
|
||||
import {IncomingMessage, ServerResponse} from "http"
|
||||
import {HTTPCookieJar} from "../kernel/HTTPCookieJar";
|
||||
import {TLSSocket} from "tls";
|
||||
@@ -84,6 +84,12 @@ export class Request extends ScopedContainer {
|
||||
/** The media types accepted by the client. */
|
||||
public readonly mediaTypes: string[];
|
||||
|
||||
/** Input parsed from the request */
|
||||
public readonly parsedInput: {[key: string]: any} = {}
|
||||
|
||||
/** Files parsed from the request. */
|
||||
public readonly uploadedFiles: {[key: string]: UniversalPath} = {}
|
||||
|
||||
constructor(
|
||||
/** The native Node.js request. */
|
||||
protected clientRequest: IncomingMessage,
|
||||
@@ -162,11 +168,22 @@ export class Request extends ScopedContainer {
|
||||
* @param key
|
||||
*/
|
||||
public input(key: string) {
|
||||
if ( key in this.parsedInput ) {
|
||||
return this.parsedInput[key]
|
||||
}
|
||||
|
||||
if ( key in this.query ) {
|
||||
return this.query[key]
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the UniversalPath instance for a file uploaded in the given field on the request.
|
||||
*/
|
||||
public file(key: string): UniversalPath | undefined {
|
||||
return this.uploadedFiles[key]
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the request accepts the given media type.
|
||||
* @param type - a mimetype, or the short forms json, xml, or html
|
||||
|
||||
Reference in New Issue
Block a user