|
| 1 | + |
| 2 | +import { APIGatewayProxyEvent } from 'aws-lambda'; |
| 3 | +import { Accepts } from 'accepts'; |
| 4 | +import { Readable } from 'stream'; |
| 5 | + |
| 6 | +export class Request extends Readable { |
| 7 | + constructor(event: APIGatewayProxyEvent); |
| 8 | + headers: { [name: string]: string }; |
| 9 | + hostname: string | null; |
| 10 | + method: string; |
| 11 | + query: { [name: string]: string } | null; |
| 12 | + path: string; |
| 13 | + params: { [name: string]: string } | null; |
| 14 | + protocol: 'http' | 'https'; |
| 15 | + secure: boolean; |
| 16 | + ips: string[]; |
| 17 | + ip: string; |
| 18 | + host: string | null; |
| 19 | + xhr: boolean; |
| 20 | + event: APIGatewayProxyEvent; |
| 21 | + accept: Accepts; |
| 22 | + /** |
| 23 | + * Check if the given `type(s)` is acceptable, returning |
| 24 | + * the best match when true, otherwise `undefined`, in which |
| 25 | + * case you should respond with 406 "Not Acceptable". |
| 26 | + * |
| 27 | + * The `type` value may be a single MIME type string |
| 28 | + * such as "application/json", an extension name |
| 29 | + * such as "json", a comma-delimited list such as "json, html, text/plain", |
| 30 | + * an argument list such as `"json", "html", "text/plain"`, |
| 31 | + * or an array `["json", "html", "text/plain"]`. When a list |
| 32 | + * or array is given, the _best_ match, if any is returned. |
| 33 | + * |
| 34 | + * Examples: |
| 35 | + * |
| 36 | + * // Accept: text/html |
| 37 | + * req.accepts('html'); |
| 38 | + * // => "html" |
| 39 | + * |
| 40 | + * // Accept: text/*, application/json |
| 41 | + * req.accepts('html'); |
| 42 | + * // => "html" |
| 43 | + * req.accepts('text/html'); |
| 44 | + * // => "text/html" |
| 45 | + * req.accepts('json, text'); |
| 46 | + * // => "json" |
| 47 | + * req.accepts('application/json'); |
| 48 | + * // => "application/json" |
| 49 | + * |
| 50 | + * // Accept: text/*, application/json |
| 51 | + * req.accepts('image/png'); |
| 52 | + * req.accepts('png'); |
| 53 | + * // => undefined |
| 54 | + * |
| 55 | + * // Accept: text/*;q=.5, application/json |
| 56 | + * req.accepts(['html', 'json']); |
| 57 | + * req.accepts('html', 'json'); |
| 58 | + * req.accepts('html, json'); |
| 59 | + * // => "json" |
| 60 | + * |
| 61 | + * @param {String|Array} type(s) |
| 62 | + * @return {String|Array|Boolean} |
| 63 | + */ |
| 64 | + accepts(args: string | string[]): string | boolean | string[]; |
| 65 | + /** |
| 66 | + * Check if the given `encoding`s are accepted. |
| 67 | + * @param {String|Array} ...encoding |
| 68 | + * @return {String|Array} |
| 69 | + */ |
| 70 | + acceptsLanguages(args: string | string[]): string | string[]; |
| 71 | + /** |
| 72 | + * Return request header. |
| 73 | + * |
| 74 | + * The `Referrer` header field is special-cased, |
| 75 | + * both `Referrer` and `Referer` are interchangeable. |
| 76 | + * |
| 77 | + * Examples: |
| 78 | + * |
| 79 | + * req.get('Content-Type'); |
| 80 | + * // => "text/plain" |
| 81 | + * |
| 82 | + * req.get('content-type'); |
| 83 | + * // => "text/plain" |
| 84 | + * |
| 85 | + * req.get('Something'); |
| 86 | + * // => undefined |
| 87 | + * |
| 88 | + * Aliased as `req.header()`. |
| 89 | + * |
| 90 | + * @param {String} key |
| 91 | + * @return {String} |
| 92 | + */ |
| 93 | + get(key: string): string | undefined; |
| 94 | + |
| 95 | + header(name: string): string | undefined; |
| 96 | + |
| 97 | + /** |
| 98 | + * Check if the incoming request contains the "Content-Type" |
| 99 | + * header field, and it contains the give mime `type`. |
| 100 | + * |
| 101 | + * Examples: |
| 102 | + * |
| 103 | + * // With Content-Type: text/html; charset=utf-8 |
| 104 | + * req.is('html'); |
| 105 | + * req.is('text/html'); |
| 106 | + * req.is('text/*'); |
| 107 | + * // => true |
| 108 | + * |
| 109 | + * // When Content-Type is application/json |
| 110 | + * req.is('json'); |
| 111 | + * req.is('application/json'); |
| 112 | + * req.is('application/*'); |
| 113 | + * // => true |
| 114 | + * |
| 115 | + * req.is('html'); |
| 116 | + * // => false |
| 117 | + * |
| 118 | + * @param {String|Array} types... |
| 119 | + * @return {String|false|null} |
| 120 | + */ |
| 121 | + is(types: string | string[]): string | boolean | null; |
| 122 | +} |
0 commit comments