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