@gjsify/http 0.3.13 → 0.3.14
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/lib/esm/client-request.js +233 -221
- package/lib/esm/constants.js +101 -101
- package/lib/esm/incoming-message.js +66 -64
- package/lib/esm/index.js +112 -97
- package/lib/esm/server-request-socket.js +69 -69
- package/lib/esm/server.js +387 -376
- package/lib/esm/validators.js +19 -19
- package/package.json +13 -13
package/lib/esm/constants.js
CHANGED
|
@@ -1,105 +1,105 @@
|
|
|
1
|
+
//#region src/constants.ts
|
|
1
2
|
const STATUS_CODES = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
3
|
+
100: "Continue",
|
|
4
|
+
101: "Switching Protocols",
|
|
5
|
+
102: "Processing",
|
|
6
|
+
103: "Early Hints",
|
|
7
|
+
200: "OK",
|
|
8
|
+
201: "Created",
|
|
9
|
+
202: "Accepted",
|
|
10
|
+
203: "Non-Authoritative Information",
|
|
11
|
+
204: "No Content",
|
|
12
|
+
205: "Reset Content",
|
|
13
|
+
206: "Partial Content",
|
|
14
|
+
207: "Multi-Status",
|
|
15
|
+
208: "Already Reported",
|
|
16
|
+
226: "IM Used",
|
|
17
|
+
300: "Multiple Choices",
|
|
18
|
+
301: "Moved Permanently",
|
|
19
|
+
302: "Found",
|
|
20
|
+
303: "See Other",
|
|
21
|
+
304: "Not Modified",
|
|
22
|
+
305: "Use Proxy",
|
|
23
|
+
307: "Temporary Redirect",
|
|
24
|
+
308: "Permanent Redirect",
|
|
25
|
+
400: "Bad Request",
|
|
26
|
+
401: "Unauthorized",
|
|
27
|
+
402: "Payment Required",
|
|
28
|
+
403: "Forbidden",
|
|
29
|
+
404: "Not Found",
|
|
30
|
+
405: "Method Not Allowed",
|
|
31
|
+
406: "Not Acceptable",
|
|
32
|
+
407: "Proxy Authentication Required",
|
|
33
|
+
408: "Request Timeout",
|
|
34
|
+
409: "Conflict",
|
|
35
|
+
410: "Gone",
|
|
36
|
+
411: "Length Required",
|
|
37
|
+
412: "Precondition Failed",
|
|
38
|
+
413: "Payload Too Large",
|
|
39
|
+
414: "URI Too Long",
|
|
40
|
+
415: "Unsupported Media Type",
|
|
41
|
+
416: "Range Not Satisfiable",
|
|
42
|
+
417: "Expectation Failed",
|
|
43
|
+
418: "I'm a Teapot",
|
|
44
|
+
421: "Misdirected Request",
|
|
45
|
+
422: "Unprocessable Entity",
|
|
46
|
+
423: "Locked",
|
|
47
|
+
424: "Failed Dependency",
|
|
48
|
+
425: "Too Early",
|
|
49
|
+
426: "Upgrade Required",
|
|
50
|
+
428: "Precondition Required",
|
|
51
|
+
429: "Too Many Requests",
|
|
52
|
+
431: "Request Header Fields Too Large",
|
|
53
|
+
451: "Unavailable For Legal Reasons",
|
|
54
|
+
500: "Internal Server Error",
|
|
55
|
+
501: "Not Implemented",
|
|
56
|
+
502: "Bad Gateway",
|
|
57
|
+
503: "Service Unavailable",
|
|
58
|
+
504: "Gateway Timeout",
|
|
59
|
+
505: "HTTP Version Not Supported",
|
|
60
|
+
506: "Variant Also Negotiates",
|
|
61
|
+
507: "Insufficient Storage",
|
|
62
|
+
508: "Loop Detected",
|
|
63
|
+
510: "Not Extended",
|
|
64
|
+
511: "Network Authentication Required"
|
|
64
65
|
};
|
|
65
66
|
const METHODS = [
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
67
|
+
"ACL",
|
|
68
|
+
"BIND",
|
|
69
|
+
"CHECKOUT",
|
|
70
|
+
"CONNECT",
|
|
71
|
+
"COPY",
|
|
72
|
+
"DELETE",
|
|
73
|
+
"GET",
|
|
74
|
+
"HEAD",
|
|
75
|
+
"LINK",
|
|
76
|
+
"LOCK",
|
|
77
|
+
"M-SEARCH",
|
|
78
|
+
"MERGE",
|
|
79
|
+
"MKACTIVITY",
|
|
80
|
+
"MKCALENDAR",
|
|
81
|
+
"MKCOL",
|
|
82
|
+
"MOVE",
|
|
83
|
+
"NOTIFY",
|
|
84
|
+
"OPTIONS",
|
|
85
|
+
"PATCH",
|
|
86
|
+
"POST",
|
|
87
|
+
"PRI",
|
|
88
|
+
"PROPFIND",
|
|
89
|
+
"PROPPATCH",
|
|
90
|
+
"PURGE",
|
|
91
|
+
"PUT",
|
|
92
|
+
"REBIND",
|
|
93
|
+
"REPORT",
|
|
94
|
+
"SEARCH",
|
|
95
|
+
"SOURCE",
|
|
96
|
+
"SUBSCRIBE",
|
|
97
|
+
"TRACE",
|
|
98
|
+
"UNBIND",
|
|
99
|
+
"UNLINK",
|
|
100
|
+
"UNLOCK",
|
|
101
|
+
"UNSUBSCRIBE"
|
|
101
102
|
];
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
};
|
|
103
|
+
|
|
104
|
+
//#endregion
|
|
105
|
+
export { METHODS, STATUS_CODES };
|
|
@@ -1,66 +1,68 @@
|
|
|
1
|
-
import { Readable } from "node:stream";
|
|
2
1
|
import { Buffer } from "node:buffer";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
2
|
+
import { Readable } from "node:stream";
|
|
3
|
+
|
|
4
|
+
//#region src/incoming-message.ts
|
|
5
|
+
/**
|
|
6
|
+
* IncomingMessage — Readable stream for HTTP request (server-side) or response (client-side).
|
|
7
|
+
*/
|
|
8
|
+
var IncomingMessage = class extends Readable {
|
|
9
|
+
httpVersion = "1.1";
|
|
10
|
+
httpVersionMajor = 1;
|
|
11
|
+
httpVersionMinor = 1;
|
|
12
|
+
headers = {};
|
|
13
|
+
rawHeaders = [];
|
|
14
|
+
method;
|
|
15
|
+
url;
|
|
16
|
+
statusCode;
|
|
17
|
+
statusMessage;
|
|
18
|
+
complete = false;
|
|
19
|
+
socket = null;
|
|
20
|
+
aborted = false;
|
|
21
|
+
/** Node.js legacy alias for socket — needed by engine.io and other HTTP consumers. */
|
|
22
|
+
get connection() {
|
|
23
|
+
return this.socket;
|
|
24
|
+
}
|
|
25
|
+
_timeoutTimer = null;
|
|
26
|
+
constructor() {
|
|
27
|
+
super();
|
|
28
|
+
}
|
|
29
|
+
_read(_size) {}
|
|
30
|
+
_autoClose() {}
|
|
31
|
+
/** Finish the readable stream with the body data (used by server-side handler). */
|
|
32
|
+
_pushBody(body) {
|
|
33
|
+
if (body && body.length > 0) {
|
|
34
|
+
this.push(Buffer.from(body));
|
|
35
|
+
}
|
|
36
|
+
this.push(null);
|
|
37
|
+
this.complete = true;
|
|
38
|
+
if (this._timeoutTimer) {
|
|
39
|
+
clearTimeout(this._timeoutTimer);
|
|
40
|
+
this._timeoutTimer = null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
setTimeout(msecs, callback) {
|
|
44
|
+
if (this._timeoutTimer) {
|
|
45
|
+
clearTimeout(this._timeoutTimer);
|
|
46
|
+
this._timeoutTimer = null;
|
|
47
|
+
}
|
|
48
|
+
if (callback) this.once("timeout", callback);
|
|
49
|
+
if (msecs > 0) {
|
|
50
|
+
this._timeoutTimer = setTimeout(() => {
|
|
51
|
+
this._timeoutTimer = null;
|
|
52
|
+
this.emit("timeout");
|
|
53
|
+
}, msecs);
|
|
54
|
+
}
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
destroy(error) {
|
|
58
|
+
if (this._timeoutTimer) {
|
|
59
|
+
clearTimeout(this._timeoutTimer);
|
|
60
|
+
this._timeoutTimer = null;
|
|
61
|
+
}
|
|
62
|
+
this.aborted = true;
|
|
63
|
+
return super.destroy(error);
|
|
64
|
+
}
|
|
66
65
|
};
|
|
66
|
+
|
|
67
|
+
//#endregion
|
|
68
|
+
export { IncomingMessage };
|
package/lib/esm/index.js
CHANGED
|
@@ -1,111 +1,126 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { METHODS, STATUS_CODES } from "./constants.js";
|
|
2
2
|
import { IncomingMessage } from "./incoming-message.js";
|
|
3
3
|
import { OutgoingMessage, Server, ServerResponse } from "./server.js";
|
|
4
4
|
import { ClientRequest } from "./client-request.js";
|
|
5
5
|
import { validateHeaderName, validateHeaderValue } from "./validators.js";
|
|
6
|
-
import { validateHeaderName as validateHeaderName2, validateHeaderValue as validateHeaderValue2 } from "./validators.js";
|
|
7
|
-
import { IncomingMessage as IncomingMessage2 } from "./incoming-message.js";
|
|
8
|
-
import { OutgoingMessage as OutgoingMessage2, Server as Server2, ServerResponse as ServerResponse2 } from "./server.js";
|
|
9
|
-
import { ClientRequest as ClientRequest2 } from "./client-request.js";
|
|
10
6
|
import { URL } from "node:url";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
7
|
+
|
|
8
|
+
//#region src/index.ts
|
|
9
|
+
/**
|
|
10
|
+
* Agent class for connection pooling.
|
|
11
|
+
* Soup.Session handles actual TCP connection pooling internally.
|
|
12
|
+
* This class provides the Node.js-compatible API surface for frameworks.
|
|
13
|
+
*/
|
|
14
|
+
var Agent = class {
|
|
15
|
+
defaultPort = 80;
|
|
16
|
+
protocol = "http:";
|
|
17
|
+
maxSockets;
|
|
18
|
+
maxTotalSockets;
|
|
19
|
+
maxFreeSockets;
|
|
20
|
+
keepAliveMsecs;
|
|
21
|
+
keepAlive;
|
|
22
|
+
scheduling;
|
|
23
|
+
/** Pending requests per host (compatibility — Soup manages internally). */
|
|
24
|
+
requests = {};
|
|
25
|
+
/** Active sockets per host (compatibility — Soup manages internally). */
|
|
26
|
+
sockets = {};
|
|
27
|
+
/** Idle sockets per host (compatibility — Soup manages internally). */
|
|
28
|
+
freeSockets = {};
|
|
29
|
+
constructor(options) {
|
|
30
|
+
this.keepAlive = options?.keepAlive ?? false;
|
|
31
|
+
this.keepAliveMsecs = options?.keepAliveMsecs ?? 1e3;
|
|
32
|
+
this.maxSockets = options?.maxSockets ?? Infinity;
|
|
33
|
+
this.maxTotalSockets = options?.maxTotalSockets ?? Infinity;
|
|
34
|
+
this.maxFreeSockets = options?.maxFreeSockets ?? 256;
|
|
35
|
+
this.scheduling = options?.scheduling ?? "lifo";
|
|
36
|
+
}
|
|
37
|
+
/** Destroy the agent and close idle connections. */
|
|
38
|
+
destroy() {}
|
|
39
|
+
/** Return a connection pool key for the given options. */
|
|
40
|
+
getName(options) {
|
|
41
|
+
let name = options.host || "localhost";
|
|
42
|
+
if (options.port) name += ":" + options.port;
|
|
43
|
+
if (options.localAddress) name += ":" + options.localAddress;
|
|
44
|
+
if (options.family === 4 || options.family === 6) name += ":" + options.family;
|
|
45
|
+
return name;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
46
48
|
const globalAgent = new Agent();
|
|
49
|
+
/**
|
|
50
|
+
* Create an HTTP server.
|
|
51
|
+
*/
|
|
47
52
|
function createServer(options, requestListener) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
if (typeof options === "function") {
|
|
54
|
+
return new Server(options);
|
|
55
|
+
}
|
|
56
|
+
return new Server(requestListener);
|
|
52
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Make an HTTP request.
|
|
60
|
+
*
|
|
61
|
+
* @param url URL string, URL object, or request options
|
|
62
|
+
* @param options Request options (if url is string/URL)
|
|
63
|
+
* @param callback Response callback
|
|
64
|
+
*/
|
|
53
65
|
function request(url, options, callback) {
|
|
54
|
-
|
|
66
|
+
return new ClientRequest(url, options, callback);
|
|
55
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Make an HTTP GET request (convenience wrapper that calls req.end() automatically).
|
|
70
|
+
*/
|
|
56
71
|
function get(url, options, callback) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
72
|
+
let opts;
|
|
73
|
+
let cb = callback;
|
|
74
|
+
if (typeof url === "string" || url instanceof URL) {
|
|
75
|
+
opts = typeof options === "object" ? {
|
|
76
|
+
...options,
|
|
77
|
+
method: "GET"
|
|
78
|
+
} : { method: "GET" };
|
|
79
|
+
if (typeof options === "function") cb = options;
|
|
80
|
+
} else {
|
|
81
|
+
opts = {
|
|
82
|
+
...url,
|
|
83
|
+
method: "GET"
|
|
84
|
+
};
|
|
85
|
+
if (typeof options === "function") cb = options;
|
|
86
|
+
url = opts;
|
|
87
|
+
}
|
|
88
|
+
const req = typeof url === "string" || url instanceof URL ? new ClientRequest(url, {
|
|
89
|
+
...opts,
|
|
90
|
+
method: "GET"
|
|
91
|
+
}, cb) : new ClientRequest({
|
|
92
|
+
...opts,
|
|
93
|
+
method: "GET"
|
|
94
|
+
}, cb);
|
|
95
|
+
req.end();
|
|
96
|
+
return req;
|
|
70
97
|
}
|
|
98
|
+
/** Max header size in bytes. */
|
|
71
99
|
const maxHeaderSize = 16384;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
ClientRequest,
|
|
96
|
-
IncomingMessage,
|
|
97
|
-
METHODS,
|
|
98
|
-
OutgoingMessage,
|
|
99
|
-
STATUS_CODES,
|
|
100
|
-
Server,
|
|
101
|
-
ServerResponse,
|
|
102
|
-
createServer,
|
|
103
|
-
index_default as default,
|
|
104
|
-
get,
|
|
105
|
-
globalAgent,
|
|
106
|
-
maxHeaderSize,
|
|
107
|
-
request,
|
|
108
|
-
setMaxIdleHTTPParsers,
|
|
109
|
-
validateHeaderName,
|
|
110
|
-
validateHeaderValue
|
|
100
|
+
/**
|
|
101
|
+
* Set the maximum number of idle HTTP parsers. Soup.Session handles
|
|
102
|
+
* connection pooling internally, so this is a no-op for compatibility.
|
|
103
|
+
* @since v18.8.0
|
|
104
|
+
*/
|
|
105
|
+
function setMaxIdleHTTPParsers(_max) {}
|
|
106
|
+
var src_default = {
|
|
107
|
+
STATUS_CODES,
|
|
108
|
+
METHODS,
|
|
109
|
+
Server,
|
|
110
|
+
IncomingMessage,
|
|
111
|
+
OutgoingMessage,
|
|
112
|
+
ServerResponse,
|
|
113
|
+
ClientRequest,
|
|
114
|
+
Agent,
|
|
115
|
+
globalAgent,
|
|
116
|
+
createServer,
|
|
117
|
+
request,
|
|
118
|
+
get,
|
|
119
|
+
validateHeaderName,
|
|
120
|
+
validateHeaderValue,
|
|
121
|
+
maxHeaderSize,
|
|
122
|
+
setMaxIdleHTTPParsers
|
|
111
123
|
};
|
|
124
|
+
|
|
125
|
+
//#endregion
|
|
126
|
+
export { Agent, ClientRequest, IncomingMessage, METHODS, OutgoingMessage, STATUS_CODES, Server, ServerResponse, createServer, src_default as default, get, globalAgent, maxHeaderSize, request, setMaxIdleHTTPParsers, validateHeaderName, validateHeaderValue };
|