-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8718cd0
commit 253ca13
Showing
42 changed files
with
745 additions
and
1,576 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/// <reference types="node" /> | ||
export interface IUploadedFile { | ||
name: string; | ||
fileName: string; | ||
mimeType: string; | ||
data: Buffer; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Multipart Parser (Finite State Machine) | ||
* usage: | ||
* const multipart = require('./multipart.js'); | ||
* const body = multipart.DemoData(); // raw body | ||
* const body = new Buffer(event['body-json'].toString(),'base64'); // AWS case | ||
* const boundary = multipart.getBoundary(event.params.header['content-type']); | ||
* const parts = multipart.Parse(body,boundary); | ||
* each part is: | ||
* { filename: 'A.txt', type: 'text/plain', data: <Buffer 41 41 41 41 42 42 42 42> } | ||
* or { name: 'key', data: <Buffer 41 41 41 41 42 42 42 42> } | ||
*/ | ||
/// <reference types="node" /> | ||
declare type Input = { | ||
filename?: string; | ||
name?: string; | ||
type: string; | ||
data: Buffer; | ||
}; | ||
export declare function parse(multipartBodyBuffer: Buffer, boundary: string): Input[]; | ||
export declare function getBoundary(header: string): string; | ||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/// <reference types="node" /> | ||
import { Bag } from '../Bag'; | ||
import { IRoute } from '../Router/Router'; | ||
import { IncomingMessage } from 'http'; | ||
import { IUploadedFile } from './IUploadedFile'; | ||
import { RequestBody } from './RequestBody'; | ||
export declare class Request { | ||
private r; | ||
private readonly _clientIp; | ||
private readonly _method; | ||
private readonly _parameters; | ||
private readonly _headers; | ||
private readonly _cookies; | ||
private readonly _query; | ||
private readonly _path; | ||
private readonly _post; | ||
private readonly _files; | ||
private readonly _body; | ||
constructor(r: IncomingMessage, body: RequestBody); | ||
/** | ||
* Returns a value from one of the available bags in the following order: | ||
* - post fields | ||
* - files | ||
* - cookies | ||
* - headers | ||
* - parameters (derived from path) | ||
* - query parameters | ||
* | ||
* @param {string} name | ||
* @return {*} | ||
*/ | ||
get(name: string): any; | ||
/** | ||
* Returns the IP address of the client. | ||
* | ||
* @return {string} | ||
*/ | ||
get clientIp(): string; | ||
/** | ||
* Returns the request path. | ||
* | ||
* @return {string} | ||
*/ | ||
get path(): string; | ||
/** | ||
* Returns the HTTP method in upper-case string representation. | ||
* | ||
* @return {string} | ||
*/ | ||
get method(): string; | ||
/** | ||
* Returns the cookie bag. | ||
* | ||
* @return {Bag} | ||
*/ | ||
get cookies(): Bag<string>; | ||
/** | ||
* Returns the headers bag. | ||
* | ||
* @return {Bag} | ||
*/ | ||
get headers(): Bag<string>; | ||
/** | ||
* Returns the query parameters bag. | ||
* | ||
* @return {Bag} | ||
*/ | ||
get query(): Bag<string | number>; | ||
/** | ||
* Returns the route parameters bag. | ||
* | ||
* @returns {Bag<string>} | ||
*/ | ||
get parameters(): Bag<string>; | ||
/** | ||
* Returns the POST-fields bag. | ||
* | ||
* @returns {Bag<string | string[]>} | ||
*/ | ||
get post(): Bag<string | string[]>; | ||
/** | ||
* Returns the files bag. | ||
* | ||
* @returns {Bag<IUploadedFile | IUploadedFile[]>} | ||
*/ | ||
get files(): Bag<IUploadedFile | IUploadedFile[]>; | ||
/** | ||
* Returns the request body as parsed JSON content. | ||
* | ||
* @returns {any} | ||
*/ | ||
get json(): any; | ||
/** | ||
* Returns true if the given route matches this request. | ||
* | ||
* @param {IRoute} route | ||
* @return {boolean} | ||
*/ | ||
isMatchingRoute(route: IRoute): boolean; | ||
/** | ||
* @param {string} pattern | ||
* @return {{regExp: RegExp, namedParams: string[]}} | ||
* @private | ||
*/ | ||
private _parsePattern; | ||
/** | ||
* Parses a cookie header into a key-value object. | ||
* | ||
* @param {string} cookieString | ||
* @returns {{[p: string]: string}} | ||
* @private | ||
*/ | ||
private _parseCookies; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/// <reference types="node" /> | ||
import { Bag } from '../Bag'; | ||
import { IUploadedFile } from './IUploadedFile'; | ||
export declare class RequestBody { | ||
readonly raw: Buffer; | ||
fields: Bag<string | string[]>; | ||
files: Bag<IUploadedFile | IUploadedFile[]>; | ||
constructor(raw: Buffer, parts: RequestBodyPart[]); | ||
private addPartToBag; | ||
} | ||
export declare type RequestBodyPart = { | ||
name: string; | ||
data: Buffer; | ||
type?: string; | ||
filename?: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/// <reference types="node" /> | ||
import { IncomingMessage, ServerResponse } from 'http'; | ||
import { RequestBody } from './RequestBody'; | ||
export declare class RequestBodyDecoder { | ||
private readonly maxUploadSize; | ||
constructor(maxUploadSize: number); | ||
/** | ||
* Attempts to deserialize the request body into data suitable for a Bag. | ||
* | ||
* If this process fails, the body is most likely uploaded content like | ||
* a binary file. | ||
*/ | ||
decode(req: IncomingMessage, res: ServerResponse): Promise<RequestBody>; | ||
/** | ||
* Parses the given body as a multipart/form-data payload. | ||
* | ||
* @param {ServerResponse} res | ||
* @param {string} type | ||
* @param {Buffer} body | ||
* @private | ||
*/ | ||
private parseMultipartFormData; | ||
/** | ||
* Parses the given body as a x-www-form-urlencoded payload. | ||
* | ||
* @param {ServerResponse} res | ||
* @param {Buffer} body | ||
* @returns {RequestBody} | ||
* @private | ||
*/ | ||
private parseFormUrlEncoded; | ||
/** | ||
* Wait for the request to complete, then return the request body. | ||
* | ||
* Sends an HTTP 413 status back to the client if the request body exceeds | ||
* the maximum upload size. | ||
* | ||
* @param {IncomingMessage} req | ||
* @param {ServerResponse} res | ||
* @returns {Promise<Buffer>} | ||
* @private | ||
*/ | ||
private getRequestBody; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { HttpStatus, Response } from './Response'; | ||
export declare class HtmlResponse extends Response { | ||
constructor(html: string, statusCode?: HttpStatus, pretty?: boolean); | ||
constructor(html: string, statusCode?: HttpStatus); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { HttpStatus, Response } from './Response'; | ||
export declare class RedirectResponse extends Response { | ||
constructor(url: string, statusCode?: HttpStatus); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.