@opra/http 1.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/cjs/express-adapter.js +155 -0
- package/cjs/http-adapter.js +24 -0
- package/cjs/http-context.js +103 -0
- package/cjs/http-handler.js +609 -0
- package/cjs/impl/http-incoming.host.js +112 -0
- package/cjs/impl/http-outgoing.host.js +207 -0
- package/cjs/impl/multipart-reader.js +196 -0
- package/cjs/impl/node-incoming-message.host.js +109 -0
- package/cjs/impl/node-outgoing-message.host.js +195 -0
- package/cjs/index.js +27 -0
- package/cjs/interfaces/http-incoming.interface.js +25 -0
- package/cjs/interfaces/http-outgoing.interface.js +22 -0
- package/cjs/interfaces/node-incoming-message.interface.js +64 -0
- package/cjs/interfaces/node-outgoing-message.interface.js +15 -0
- package/cjs/package.json +3 -0
- package/cjs/type-guards.js +22 -0
- package/cjs/utils/body-reader.js +216 -0
- package/cjs/utils/common.js +67 -0
- package/cjs/utils/concat-readable.js +19 -0
- package/cjs/utils/convert-to-headers.js +64 -0
- package/cjs/utils/convert-to-raw-headers.js +23 -0
- package/cjs/utils/match-known-fields.js +49 -0
- package/cjs/utils/wrap-exception.js +33 -0
- package/esm/express-adapter.js +150 -0
- package/esm/http-adapter.js +20 -0
- package/esm/http-context.js +98 -0
- package/esm/http-handler.js +604 -0
- package/esm/impl/http-incoming.host.js +107 -0
- package/esm/impl/http-outgoing.host.js +202 -0
- package/esm/impl/multipart-reader.js +191 -0
- package/esm/impl/node-incoming-message.host.js +105 -0
- package/esm/impl/node-outgoing-message.host.js +191 -0
- package/esm/index.js +23 -0
- package/esm/interfaces/http-incoming.interface.js +22 -0
- package/esm/interfaces/http-outgoing.interface.js +19 -0
- package/esm/interfaces/node-incoming-message.interface.js +61 -0
- package/esm/interfaces/node-outgoing-message.interface.js +12 -0
- package/esm/package.json +3 -0
- package/esm/type-guards.js +16 -0
- package/esm/utils/body-reader.js +211 -0
- package/esm/utils/common.js +61 -0
- package/esm/utils/concat-readable.js +16 -0
- package/esm/utils/convert-to-headers.js +60 -0
- package/esm/utils/convert-to-raw-headers.js +20 -0
- package/esm/utils/match-known-fields.js +45 -0
- package/esm/utils/wrap-exception.js +30 -0
- package/i18n/en/error.json +21 -0
- package/package.json +89 -0
- package/types/express-adapter.d.ts +13 -0
- package/types/http-adapter.d.ts +32 -0
- package/types/http-context.d.ts +44 -0
- package/types/http-handler.d.ts +74 -0
- package/types/impl/http-incoming.host.d.ts +22 -0
- package/types/impl/http-outgoing.host.d.ts +17 -0
- package/types/impl/multipart-reader.d.ts +46 -0
- package/types/impl/node-incoming-message.host.d.ts +45 -0
- package/types/impl/node-outgoing-message.host.d.ts +49 -0
- package/types/index.d.cts +22 -0
- package/types/index.d.ts +22 -0
- package/types/interfaces/http-incoming.interface.d.ts +192 -0
- package/types/interfaces/http-outgoing.interface.d.ts +144 -0
- package/types/interfaces/node-incoming-message.interface.d.ts +36 -0
- package/types/interfaces/node-outgoing-message.interface.d.ts +27 -0
- package/types/type-guards.d.ts +8 -0
- package/types/utils/body-reader.d.ts +38 -0
- package/types/utils/common.d.ts +17 -0
- package/types/utils/concat-readable.d.ts +2 -0
- package/types/utils/convert-to-headers.d.ts +2 -0
- package/types/utils/convert-to-raw-headers.d.ts +2 -0
- package/types/utils/match-known-fields.d.ts +6 -0
- package/types/utils/wrap-exception.d.ts +2 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import type { Options as RangeParserOptions, Ranges as RangeParserRanges, Result as RangeParserResult } from 'range-parser';
|
|
2
|
+
import { BodyReader } from '../utils/body-reader.js';
|
|
3
|
+
import type { HttpOutgoing } from './http-outgoing.interface.js';
|
|
4
|
+
import { NodeIncomingMessage } from './node-incoming-message.interface.js';
|
|
5
|
+
/**
|
|
6
|
+
* @interface HttpIncoming
|
|
7
|
+
*/
|
|
8
|
+
export interface HttpIncoming extends NodeIncomingMessage {
|
|
9
|
+
res: HttpOutgoing;
|
|
10
|
+
baseUrl: string;
|
|
11
|
+
originalUrl: string;
|
|
12
|
+
/**
|
|
13
|
+
* Return the protocol string "http" or "https"
|
|
14
|
+
* When the "X-Forwarded-Proto" header field will be trusted
|
|
15
|
+
* and used if present.
|
|
16
|
+
*/
|
|
17
|
+
protocol: string;
|
|
18
|
+
/**
|
|
19
|
+
* Return the remote address from the trusted proxy.
|
|
20
|
+
*
|
|
21
|
+
* This is the remote address on the socket unless "trust proxy" is set.
|
|
22
|
+
*/
|
|
23
|
+
ip: string;
|
|
24
|
+
/**
|
|
25
|
+
* When "trust proxy" is set, trusted proxy addresses + client.
|
|
26
|
+
*
|
|
27
|
+
* For example if the value were "client, proxy1, proxy2"
|
|
28
|
+
* you would receive the array `["client", "proxy1", "proxy2"]`
|
|
29
|
+
* where "proxy2" is the furthest down-stream and "proxy1" and
|
|
30
|
+
* "proxy2" were trusted.
|
|
31
|
+
*/
|
|
32
|
+
ips: string[];
|
|
33
|
+
/**
|
|
34
|
+
* Short-hand for:
|
|
35
|
+
* req.protocol === 'https'
|
|
36
|
+
*/
|
|
37
|
+
secure: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Used for signed cookies
|
|
40
|
+
*/
|
|
41
|
+
secret?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Parse the "Host" header field to a hostname.
|
|
44
|
+
*
|
|
45
|
+
* When the "trust proxy" setting trusts the socket
|
|
46
|
+
* address, the "X-Forwarded-Host" header field will
|
|
47
|
+
* be trusted.
|
|
48
|
+
*/
|
|
49
|
+
hostname?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Check if the request is fresh, aka
|
|
52
|
+
* Last-Modified and/or the ETag still match.
|
|
53
|
+
*/
|
|
54
|
+
fresh: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Path parameter values
|
|
57
|
+
*/
|
|
58
|
+
params: Record<string, any>;
|
|
59
|
+
/**
|
|
60
|
+
* Cookie parameter values
|
|
61
|
+
*/
|
|
62
|
+
cookies?: Record<string, any>;
|
|
63
|
+
/**
|
|
64
|
+
* Return request header.
|
|
65
|
+
*
|
|
66
|
+
* The `Referrer` header field is special-cased,
|
|
67
|
+
* both `Referrer` and `Referer` are interchangeable.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* req.get('Content-Type');
|
|
71
|
+
* // => "text/plain"
|
|
72
|
+
*
|
|
73
|
+
* req.get('content-type');
|
|
74
|
+
* // => "text/plain"
|
|
75
|
+
*
|
|
76
|
+
* req.get('Something');
|
|
77
|
+
* // => undefined
|
|
78
|
+
*
|
|
79
|
+
*/
|
|
80
|
+
header(name: 'set-cookie'): string[] | undefined;
|
|
81
|
+
header(name: string): string | undefined;
|
|
82
|
+
get(name: 'set-cookie'): string[] | undefined;
|
|
83
|
+
get(name: string): string | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Check if the given `type(s)` is acceptable, returning
|
|
86
|
+
* the best match when true, otherwise `undefined`, in which
|
|
87
|
+
* case you should respond with 406 "Not Acceptable".
|
|
88
|
+
*
|
|
89
|
+
* The `type` value may be a single mime type string
|
|
90
|
+
* such as "application/json", the extension name
|
|
91
|
+
* such as "json", a comma-delimited list such as "json, html, text/plain",
|
|
92
|
+
* or an array `["json", "html", "text/plain"]`. When a list
|
|
93
|
+
* or array is given the _best_ match, if any is returned.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* // Accept: text/html
|
|
97
|
+
* req.accepts('html');
|
|
98
|
+
* // => "html"
|
|
99
|
+
*
|
|
100
|
+
* // Accept: text/*, application/json
|
|
101
|
+
* req.accepts('html');
|
|
102
|
+
* // => "html"
|
|
103
|
+
* req.accepts('text/html');
|
|
104
|
+
* // => "text/html"
|
|
105
|
+
* req.accepts('json, text');
|
|
106
|
+
* // => "json"
|
|
107
|
+
* req.accepts('application/json');
|
|
108
|
+
* // => "application/json"
|
|
109
|
+
*
|
|
110
|
+
* // Accept: text/*, application/json
|
|
111
|
+
* req.accepts('image/png');
|
|
112
|
+
* req.accepts('png');
|
|
113
|
+
* // => undefined
|
|
114
|
+
*
|
|
115
|
+
* // Accept: text/*;q=.5, application/json
|
|
116
|
+
* req.accepts(['html', 'json']);
|
|
117
|
+
* req.accepts('html, json');
|
|
118
|
+
* // => "json"
|
|
119
|
+
*/
|
|
120
|
+
accepts(): string[];
|
|
121
|
+
accepts(type: string): string | false;
|
|
122
|
+
accepts(type: string[]): string | false;
|
|
123
|
+
accepts(...type: string[]): string | false;
|
|
124
|
+
/**
|
|
125
|
+
* Returns the first accepted charset of the specified character sets,
|
|
126
|
+
* based on the request's Accept-Charset HTTP header field.
|
|
127
|
+
* If none of the specified charsets is accepted, returns false.
|
|
128
|
+
*
|
|
129
|
+
* For more information, or if you have issues or concerns, see accepts.
|
|
130
|
+
*/
|
|
131
|
+
acceptsCharsets(): string[];
|
|
132
|
+
acceptsCharsets(charsets: string[]): string | false;
|
|
133
|
+
acceptsCharsets(...charset: string[]): string | false;
|
|
134
|
+
/**
|
|
135
|
+
* Returns the first accepted encoding of the specified encodings,
|
|
136
|
+
* based on the request's Accept-Encoding HTTP header field.
|
|
137
|
+
* If none of the specified encodings is accepted, returns false.
|
|
138
|
+
*
|
|
139
|
+
* For more information, or if you have issues or concerns, see accepts.
|
|
140
|
+
*/
|
|
141
|
+
acceptsEncodings(): string[];
|
|
142
|
+
acceptsEncodings(encodings: string[]): string | false;
|
|
143
|
+
acceptsEncodings(...encoding: string[]): string | false;
|
|
144
|
+
/**
|
|
145
|
+
* Returns the first accepted language of the specified languages,
|
|
146
|
+
* based on the request's Accept-Language HTTP header field.
|
|
147
|
+
* If none of the specified languages is accepted, returns false.
|
|
148
|
+
*
|
|
149
|
+
* For more information, or if you have issues or concerns, see accepts.
|
|
150
|
+
*/
|
|
151
|
+
acceptsLanguages(): string[];
|
|
152
|
+
acceptsLanguages(lang: string): string | false;
|
|
153
|
+
acceptsLanguages(lang: string[]): string | false;
|
|
154
|
+
acceptsLanguages(...lang: string[]): string | false;
|
|
155
|
+
/**
|
|
156
|
+
* Check if the incoming request contains the "Content-Type"
|
|
157
|
+
* header field, and it contains the give mime `type`.
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* // With Content-Type: text/html; charset=utf-8
|
|
161
|
+
* req.is('html');
|
|
162
|
+
* req.is('text/html');
|
|
163
|
+
* req.is('text/*');
|
|
164
|
+
* // => true
|
|
165
|
+
*
|
|
166
|
+
* // When Content-Type is application/json
|
|
167
|
+
* req.is('json');
|
|
168
|
+
* req.is('application/json');
|
|
169
|
+
* req.is('application/*');
|
|
170
|
+
* // => true
|
|
171
|
+
*
|
|
172
|
+
* req.is('html');
|
|
173
|
+
* // => false
|
|
174
|
+
*/
|
|
175
|
+
is(type: string | string[]): string | false | null;
|
|
176
|
+
is(...types: string[]): string | false | null;
|
|
177
|
+
/**
|
|
178
|
+
* Parse Range header field, capping to the given `size`.
|
|
179
|
+
*/
|
|
180
|
+
range(size: number, options?: RangeParserOptions): RangeParserRanges | RangeParserResult | undefined;
|
|
181
|
+
/**
|
|
182
|
+
* Receives the body
|
|
183
|
+
* @param options
|
|
184
|
+
*/
|
|
185
|
+
readBody(options: BodyReader.Options): Promise<string | Buffer | undefined>;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* @namespace HttpIncoming
|
|
189
|
+
*/
|
|
190
|
+
export declare namespace HttpIncoming {
|
|
191
|
+
function from(instance: HttpIncoming | NodeIncomingMessage.Initiator | string | Iterable<any> | AsyncIterable<any>): HttpIncoming;
|
|
192
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { type StrictOmit } from 'ts-gems';
|
|
2
|
+
import type { HttpIncoming } from './http-incoming.interface.js';
|
|
3
|
+
import { NodeOutgoingMessage } from './node-outgoing-message.interface.js';
|
|
4
|
+
export interface HttpOutgoing extends StrictOmit<NodeOutgoingMessage, 'req' | 'appendHeader' | 'setHeader'> {
|
|
5
|
+
req: HttpIncoming;
|
|
6
|
+
readonly finished?: boolean;
|
|
7
|
+
appendHeader(name: string, value: string | readonly string[]): this;
|
|
8
|
+
setHeader(name: string, value: number | string | readonly string[]): this;
|
|
9
|
+
/**
|
|
10
|
+
* Set _Content-Disposition_ header to _attachment_ with optional `filename`.
|
|
11
|
+
*/
|
|
12
|
+
attachment(filename?: string): this;
|
|
13
|
+
/** Clear cookie `name`. */
|
|
14
|
+
clearCookie(name: string, options?: CookieOptions): this;
|
|
15
|
+
/**
|
|
16
|
+
* Set cookie `name` to `val`, with the given `options`.
|
|
17
|
+
*
|
|
18
|
+
* Options:
|
|
19
|
+
*
|
|
20
|
+
* - `maxAge` max-age in milliseconds, converted to `expires`
|
|
21
|
+
* - `signed` sign the cookie
|
|
22
|
+
* - `path` defaults to "/"
|
|
23
|
+
*
|
|
24
|
+
* Examples:
|
|
25
|
+
*
|
|
26
|
+
* // "Remember Me" for 15 minutes
|
|
27
|
+
* res.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true });
|
|
28
|
+
*
|
|
29
|
+
* // save as above
|
|
30
|
+
* res.cookie('rememberme', '1', { maxAge: 900000, httpOnly: true })
|
|
31
|
+
*/
|
|
32
|
+
cookie(name: string, val: string, options: CookieOptions): this;
|
|
33
|
+
cookie(name: string, val: any, options: CookieOptions): this;
|
|
34
|
+
cookie(name: string, val: any): this;
|
|
35
|
+
/**
|
|
36
|
+
* Set _Content-Type_ response header with `type` through `mime.lookup()`
|
|
37
|
+
* when it does not contain "/", or set the Content-Type to `type` otherwise.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* res.type('.html');
|
|
41
|
+
* res.type('html');
|
|
42
|
+
* res.type('json');
|
|
43
|
+
* res.type('application/json');
|
|
44
|
+
* res.type('png');
|
|
45
|
+
*/
|
|
46
|
+
contentType(type: string): this;
|
|
47
|
+
/**
|
|
48
|
+
* Set Link header field with the given `links`.
|
|
49
|
+
*
|
|
50
|
+
* Examples:
|
|
51
|
+
*
|
|
52
|
+
* res.links({
|
|
53
|
+
* next: 'http://api.example.com/users?page=2',
|
|
54
|
+
* last: 'http://api.example.com/users?page=5'
|
|
55
|
+
* });
|
|
56
|
+
*/
|
|
57
|
+
links(links: Record<string, string>): this;
|
|
58
|
+
/**
|
|
59
|
+
* Set the location header to `url`.
|
|
60
|
+
*
|
|
61
|
+
* The given `url` can also be the name of a mapped url, for
|
|
62
|
+
* example by default express supports "back" which redirects
|
|
63
|
+
* to the _Referrer_ or _Referer_ headers or "/".
|
|
64
|
+
*
|
|
65
|
+
* Examples:
|
|
66
|
+
*
|
|
67
|
+
* res.location('/foo/bar').;
|
|
68
|
+
* res.location('http://example.com');
|
|
69
|
+
* res.location('../login'); // /blog/post/1 -> /blog/login
|
|
70
|
+
*
|
|
71
|
+
* Mounting:
|
|
72
|
+
*
|
|
73
|
+
* When an application is mounted and `res.location()`
|
|
74
|
+
* is given a path that does _not_ lead with "/" it becomes
|
|
75
|
+
* relative to the mount-point. For example if the application
|
|
76
|
+
* is mounted at "/blog", the following would become "/blog/login".
|
|
77
|
+
*
|
|
78
|
+
* res.location('login');
|
|
79
|
+
*
|
|
80
|
+
* While the leading slash would result in a location of "/login":
|
|
81
|
+
*
|
|
82
|
+
* res.location('/login');
|
|
83
|
+
*/
|
|
84
|
+
location(url: string): this;
|
|
85
|
+
/**
|
|
86
|
+
* Redirect to the given `url` with optional response `status`
|
|
87
|
+
* defaulting to 302.
|
|
88
|
+
*
|
|
89
|
+
* The resulting `url` is determined by `res.location()`, so
|
|
90
|
+
* it will play nicely with mounted apps, relative paths,
|
|
91
|
+
* `"back"` etc.
|
|
92
|
+
*
|
|
93
|
+
* Examples:
|
|
94
|
+
*
|
|
95
|
+
* res.redirect('back');
|
|
96
|
+
* res.redirect('/foo/bar');
|
|
97
|
+
* res.redirect('http://example.com');
|
|
98
|
+
* res.redirect(301, 'http://example.com');
|
|
99
|
+
* res.redirect('http://example.com', 301);
|
|
100
|
+
* res.redirect('../login'); // /blog/post/1 -> /blog/login
|
|
101
|
+
*/
|
|
102
|
+
redirect(url: string): void;
|
|
103
|
+
redirect(status: number, url: string): void;
|
|
104
|
+
/**
|
|
105
|
+
* Set status `code`.
|
|
106
|
+
*/
|
|
107
|
+
status(code: number): this;
|
|
108
|
+
/**
|
|
109
|
+
* Send given HTTP status code.
|
|
110
|
+
*
|
|
111
|
+
* Sets the response status to `statusCode` and the body of the
|
|
112
|
+
* response to the standard description from node's http.STATUS_CODES
|
|
113
|
+
* or the statusCode number if no description.
|
|
114
|
+
*/
|
|
115
|
+
sendStatus(statusCode: number): this;
|
|
116
|
+
/**
|
|
117
|
+
* Send a response.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* res.send(new Buffer('wahoo'));
|
|
121
|
+
* res.send({ some: 'json' });
|
|
122
|
+
* res.send('<p>some html</p>');
|
|
123
|
+
* res.status(404).send('Sorry, cant find that');
|
|
124
|
+
*/
|
|
125
|
+
send(body?: any): this;
|
|
126
|
+
}
|
|
127
|
+
export interface CookieOptions {
|
|
128
|
+
secret?: string;
|
|
129
|
+
maxAge?: number;
|
|
130
|
+
signed?: boolean;
|
|
131
|
+
expires?: Date;
|
|
132
|
+
httpOnly?: boolean;
|
|
133
|
+
path?: string;
|
|
134
|
+
domain?: string;
|
|
135
|
+
secure?: boolean;
|
|
136
|
+
encode?: (val: string) => string;
|
|
137
|
+
sameSite?: boolean | 'lax' | 'strict' | 'none';
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* @namespace HttpIncoming
|
|
141
|
+
*/
|
|
142
|
+
export declare namespace HttpOutgoing {
|
|
143
|
+
function from(instance: HttpOutgoing | NodeOutgoingMessage.Initiator): HttpOutgoing;
|
|
144
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import http from 'http';
|
|
2
|
+
import { Readable } from 'stream';
|
|
3
|
+
/**
|
|
4
|
+
* @interface NodeIncomingMessage
|
|
5
|
+
*/
|
|
6
|
+
export interface NodeIncomingMessage extends Readable, Pick<http.IncomingMessage, 'httpVersion' | 'httpVersionMajor' | 'httpVersionMinor' | 'complete' | 'headers' | 'trailers' | 'rawHeaders' | 'rawTrailers' | 'method' | 'url'> {
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @namespace NodeIncomingMessage
|
|
11
|
+
*/
|
|
12
|
+
export declare namespace NodeIncomingMessage {
|
|
13
|
+
interface Initiator {
|
|
14
|
+
httpVersionMajor?: number;
|
|
15
|
+
httpVersionMinor?: number;
|
|
16
|
+
method?: string;
|
|
17
|
+
url?: string;
|
|
18
|
+
headers?: Record<string, any> | string[];
|
|
19
|
+
trailers?: Record<string, any> | string[];
|
|
20
|
+
params?: Record<string, any>;
|
|
21
|
+
cookies?: Record<string, any>;
|
|
22
|
+
body?: any;
|
|
23
|
+
ip?: string;
|
|
24
|
+
ips?: string[];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Creates a new NodeIncomingMessage from given argument
|
|
28
|
+
* @param iterable
|
|
29
|
+
*/
|
|
30
|
+
function from(iterable: string | Iterable<any> | AsyncIterable<any> | Initiator): NodeIncomingMessage;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a new NodeIncomingMessage from given argument
|
|
33
|
+
* @param iterable
|
|
34
|
+
*/
|
|
35
|
+
function fromAsync(iterable: string | Iterable<any> | AsyncIterable<any> | Initiator): Promise<NodeIncomingMessage>;
|
|
36
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import http, { type OutgoingHttpHeaders } from 'http';
|
|
2
|
+
import { Writable } from 'stream';
|
|
3
|
+
import { NodeIncomingMessage } from './node-incoming-message.interface.js';
|
|
4
|
+
export interface NodeOutgoingMessage extends Writable, Pick<http.ServerResponse, 'addTrailers' | 'getHeader' | 'getHeaders' | 'getHeaderNames' | 'flushHeaders' | 'removeHeader' | 'hasHeader' | 'headersSent' | 'statusCode' | 'statusMessage' | 'sendDate'> {
|
|
5
|
+
req: NodeIncomingMessage;
|
|
6
|
+
getRawHeaderNames(): string[];
|
|
7
|
+
appendHeader(name: string, value: string | readonly string[]): this;
|
|
8
|
+
setHeader(name: string, value: number | string | readonly string[]): this;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
* @namespace NodeOutgoingMessage
|
|
13
|
+
*/
|
|
14
|
+
export declare namespace NodeOutgoingMessage {
|
|
15
|
+
interface Initiator {
|
|
16
|
+
req: NodeIncomingMessage;
|
|
17
|
+
statusCode?: number;
|
|
18
|
+
statusMessage?: string;
|
|
19
|
+
headers?: OutgoingHttpHeaders | Headers | Map<string, any> | string[];
|
|
20
|
+
chunkedEncoding?: boolean;
|
|
21
|
+
sendDate?: boolean;
|
|
22
|
+
strictContentLength?: boolean;
|
|
23
|
+
body?: string | Iterable<any> | AsyncIterable<any> | Object;
|
|
24
|
+
parsedUrl?: URL;
|
|
25
|
+
}
|
|
26
|
+
function from(init: Initiator): NodeOutgoingMessage;
|
|
27
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { HttpIncoming } from './interfaces/http-incoming.interface.js';
|
|
2
|
+
import type { HttpOutgoing } from './interfaces/http-outgoing.interface.js';
|
|
3
|
+
import type { NodeIncomingMessage } from './interfaces/node-incoming-message.interface.js';
|
|
4
|
+
import type { NodeOutgoingMessage } from './interfaces/node-outgoing-message.interface.js';
|
|
5
|
+
export declare function isNodeIncomingMessage(v: any): v is NodeIncomingMessage;
|
|
6
|
+
export declare function isHttpIncoming(v: any): v is HttpIncoming;
|
|
7
|
+
export declare function isNodeOutgoingMessage(v: any): v is NodeOutgoingMessage;
|
|
8
|
+
export declare function isHttpOutgoing(v: any): v is HttpOutgoing;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import nodeStream from 'node:stream';
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import type { HttpIncoming } from '../interfaces/http-incoming.interface.js';
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @namespace BodyReader
|
|
7
|
+
*/
|
|
8
|
+
export declare namespace BodyReader {
|
|
9
|
+
interface Options {
|
|
10
|
+
limit?: number | string;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
type Callback = (...args: any[]) => any;
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @class BodyReader
|
|
17
|
+
*/
|
|
18
|
+
export declare class BodyReader extends EventEmitter {
|
|
19
|
+
readonly req: HttpIncoming;
|
|
20
|
+
limit?: number;
|
|
21
|
+
protected _stream?: nodeStream.Readable;
|
|
22
|
+
protected _buffer?: string | Buffer[];
|
|
23
|
+
protected _completed?: boolean | undefined;
|
|
24
|
+
protected _receivedSize: number;
|
|
25
|
+
protected cleanup: Callback;
|
|
26
|
+
protected onAborted: Callback;
|
|
27
|
+
protected onData: Callback;
|
|
28
|
+
protected onEnd: Callback;
|
|
29
|
+
constructor(req: HttpIncoming, options?: BodyReader.Options);
|
|
30
|
+
read(): Promise<string | Buffer | undefined>;
|
|
31
|
+
protected _onEnd(error: any): void;
|
|
32
|
+
protected _cleanup(): void;
|
|
33
|
+
protected _onAborted(): void;
|
|
34
|
+
protected _onData(chunk: Buffer | string): void;
|
|
35
|
+
static read(req: HttpIncoming, options?: BodyReader.Options): Promise<string | Buffer | undefined>;
|
|
36
|
+
protected static encoderPipeline(req: HttpIncoming): nodeStream.Readable;
|
|
37
|
+
}
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verifies that the given val is a valid HTTP token
|
|
3
|
+
* per the rules defined in RFC 7230
|
|
4
|
+
* See https://tools.ietf.org/html/rfc7230#section-3.2.6
|
|
5
|
+
*
|
|
6
|
+
* https://github.com/nodejs/node/blob/main/lib/_http_common.js
|
|
7
|
+
*/
|
|
8
|
+
export declare function checkIsHttpToken(val: any): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* This function removes unnecessary frames from Node.js core errors.
|
|
11
|
+
*
|
|
12
|
+
* https://github.com/nodejs/node/blob/main/lib/internal/errors.js
|
|
13
|
+
*/
|
|
14
|
+
export declare function hideStackFrames(fn: Function): Function;
|
|
15
|
+
export declare const validateHeaderName: Function;
|
|
16
|
+
export declare const validateHeaderValue: Function;
|
|
17
|
+
export declare function validateString(value: any, name?: string): void;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const NO_DUPLICATES_FIELD = 0;
|
|
2
|
+
export declare const COMMA_DELIMITED_FIELD = 1;
|
|
3
|
+
export declare const SEMICOLON_DELIMITED_FIELD = 2;
|
|
4
|
+
export declare const ARRAY_FIELD = 3;
|
|
5
|
+
export type FIELD_FLAG = typeof NO_DUPLICATES_FIELD | typeof COMMA_DELIMITED_FIELD | typeof SEMICOLON_DELIMITED_FIELD | typeof ARRAY_FIELD;
|
|
6
|
+
export declare function matchKnownFields(field: string): [string, FIELD_FLAG];
|