enhancement(extollo/extollo#2): add kernel module for parsing request body contents, uploading files
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2021-03-30 21:15:39 -05:00
parent 0be0d73917
commit a4edecee00
6 changed files with 158 additions and 1 deletions

View File

@@ -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