react-native-nitro-net 0.1.5 → 0.3.0
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/README.md +122 -12
- package/android/libs/arm64-v8a/librust_c_net.so +0 -0
- package/android/libs/armeabi-v7a/librust_c_net.so +0 -0
- package/android/libs/x86/librust_c_net.so +0 -0
- package/android/libs/x86_64/librust_c_net.so +0 -0
- package/cpp/HybridHttpParser.hpp +67 -0
- package/cpp/HybridNetDriver.hpp +74 -0
- package/cpp/HybridNetServerDriver.hpp +16 -0
- package/cpp/HybridNetSocketDriver.hpp +176 -0
- package/cpp/NetBindings.hpp +67 -1
- package/ios/Frameworks/RustCNet.xcframework/ios-arm64/RustCNet.framework/RustCNet +0 -0
- package/ios/Frameworks/RustCNet.xcframework/ios-arm64_x86_64-simulator/RustCNet.framework/RustCNet +0 -0
- package/lib/Net.nitro.d.ts +46 -1
- package/lib/Net.nitro.js +3 -1
- package/lib/http.d.ts +203 -0
- package/lib/http.js +1138 -0
- package/lib/https.d.ts +24 -0
- package/lib/https.js +144 -0
- package/lib/index.d.ts +50 -11
- package/lib/index.js +179 -31
- package/lib/tls.d.ts +145 -0
- package/lib/tls.js +521 -0
- package/nitrogen/generated/android/RustCNet+autolinking.cmake +2 -0
- package/nitrogen/generated/android/RustCNetOnLoad.cpp +2 -0
- package/nitrogen/generated/android/c++/JHybridHttpParserSpec.cpp +54 -0
- package/nitrogen/generated/android/c++/JHybridHttpParserSpec.hpp +65 -0
- package/nitrogen/generated/android/c++/JHybridNetDriverSpec.cpp +47 -1
- package/nitrogen/generated/android/c++/JHybridNetDriverSpec.hpp +9 -0
- package/nitrogen/generated/android/c++/JHybridNetServerDriverSpec.cpp +8 -0
- package/nitrogen/generated/android/c++/JHybridNetServerDriverSpec.hpp +2 -0
- package/nitrogen/generated/android/c++/JHybridNetSocketDriverSpec.cpp +79 -0
- package/nitrogen/generated/android/c++/JHybridNetSocketDriverSpec.hpp +17 -0
- package/nitrogen/generated/android/c++/JNetConfig.hpp +7 -3
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/net/HybridHttpParserSpec.kt +58 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/net/HybridNetDriverSpec.kt +37 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/net/HybridNetServerDriverSpec.kt +8 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/net/HybridNetSocketDriverSpec.kt +68 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/net/NetConfig.kt +6 -3
- package/nitrogen/generated/ios/RustCNet-Swift-Cxx-Bridge.cpp +17 -0
- package/nitrogen/generated/ios/RustCNet-Swift-Cxx-Bridge.hpp +118 -41
- package/nitrogen/generated/ios/RustCNet-Swift-Cxx-Umbrella.hpp +5 -0
- package/nitrogen/generated/ios/c++/HybridHttpParserSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridHttpParserSpecSwift.hpp +79 -0
- package/nitrogen/generated/ios/c++/HybridNetDriverSpecSwift.hpp +69 -0
- package/nitrogen/generated/ios/c++/HybridNetServerDriverSpecSwift.hpp +12 -0
- package/nitrogen/generated/ios/c++/HybridNetSocketDriverSpecSwift.hpp +123 -0
- package/nitrogen/generated/ios/swift/HybridHttpParserSpec.swift +56 -0
- package/nitrogen/generated/ios/swift/HybridHttpParserSpec_cxx.swift +131 -0
- package/nitrogen/generated/ios/swift/HybridNetDriverSpec.swift +9 -0
- package/nitrogen/generated/ios/swift/HybridNetDriverSpec_cxx.swift +133 -0
- package/nitrogen/generated/ios/swift/HybridNetServerDriverSpec.swift +2 -0
- package/nitrogen/generated/ios/swift/HybridNetServerDriverSpec_cxx.swift +36 -0
- package/nitrogen/generated/ios/swift/HybridNetSocketDriverSpec.swift +17 -0
- package/nitrogen/generated/ios/swift/HybridNetSocketDriverSpec_cxx.swift +314 -0
- package/nitrogen/generated/ios/swift/NetConfig.swift +19 -1
- package/nitrogen/generated/shared/c++/HybridHttpParserSpec.cpp +21 -0
- package/nitrogen/generated/shared/c++/HybridHttpParserSpec.hpp +63 -0
- package/nitrogen/generated/shared/c++/HybridNetDriverSpec.cpp +9 -0
- package/nitrogen/generated/shared/c++/HybridNetDriverSpec.hpp +13 -0
- package/nitrogen/generated/shared/c++/HybridNetServerDriverSpec.cpp +2 -0
- package/nitrogen/generated/shared/c++/HybridNetServerDriverSpec.hpp +2 -0
- package/nitrogen/generated/shared/c++/HybridNetSocketDriverSpec.cpp +17 -0
- package/nitrogen/generated/shared/c++/HybridNetSocketDriverSpec.hpp +18 -0
- package/nitrogen/generated/shared/c++/NetConfig.hpp +6 -2
- package/package.json +7 -5
- package/react-native-nitro-net.podspec +1 -3
- package/src/Net.nitro.ts +44 -1
- package/src/http.ts +1304 -0
- package/src/https.ts +127 -0
- package/src/index.ts +167 -27
- package/src/tls.ts +608 -0
package/cpp/NetBindings.hpp
CHANGED
|
@@ -21,11 +21,34 @@ void net_init_with_config(NetCallback callback, void *context,
|
|
|
21
21
|
// Socket
|
|
22
22
|
uint32_t net_create_socket();
|
|
23
23
|
void net_connect(uint32_t id, const char *host, int port);
|
|
24
|
+
void net_connect_tls(uint32_t id, const char *host, int port,
|
|
25
|
+
const char *server_name, int reject_unauthorized);
|
|
26
|
+
void net_connect_tls_with_context(uint32_t id, const char *host, int port,
|
|
27
|
+
const char *server_name,
|
|
28
|
+
int reject_unauthorized,
|
|
29
|
+
uint32_t secure_context_id);
|
|
30
|
+
size_t net_get_authorization_error(uint32_t id, char *buf, size_t len);
|
|
31
|
+
size_t net_get_protocol(uint32_t id, char *buf, size_t len);
|
|
32
|
+
size_t net_get_cipher(uint32_t id, char *buf, size_t len);
|
|
33
|
+
size_t net_get_alpn(uint32_t id, char *buf, size_t len);
|
|
34
|
+
size_t net_get_peer_certificate_json(uint32_t id, char *buf, size_t len);
|
|
35
|
+
void net_socket_enable_keylog(uint32_t id);
|
|
24
36
|
void net_write(uint32_t id, const uint8_t *data, size_t len);
|
|
25
37
|
void net_close(uint32_t id);
|
|
26
38
|
void net_destroy_socket(uint32_t id);
|
|
27
39
|
void net_socket_reset_and_destroy(uint32_t id);
|
|
28
40
|
|
|
41
|
+
// Phase 13: Advanced TLS inspection
|
|
42
|
+
size_t net_get_ephemeral_key_info(uint32_t id, char *buf, size_t len);
|
|
43
|
+
size_t net_get_shared_sigalgs(uint32_t id, char *buf, size_t len);
|
|
44
|
+
|
|
45
|
+
// TLS Features: enableTrace and exportKeyingMaterial
|
|
46
|
+
void net_socket_enable_trace(uint32_t id);
|
|
47
|
+
int net_socket_export_keying_material(uint32_t id, size_t length,
|
|
48
|
+
const char *label, const uint8_t *context,
|
|
49
|
+
size_t context_len, uint8_t *buf,
|
|
50
|
+
size_t buf_len);
|
|
51
|
+
|
|
29
52
|
// New Options
|
|
30
53
|
void net_set_nodelay(uint32_t id, bool enable);
|
|
31
54
|
void net_set_keepalive(uint32_t id, bool enable, uint64_t delay_ms);
|
|
@@ -41,28 +64,71 @@ void net_pause(uint32_t id);
|
|
|
41
64
|
void net_resume(uint32_t id);
|
|
42
65
|
void net_shutdown(uint32_t id);
|
|
43
66
|
|
|
44
|
-
// IPC
|
|
67
|
+
// IPC / Unix Domain Sockets
|
|
45
68
|
void net_connect_unix(uint32_t id, const char *path);
|
|
46
69
|
void net_listen_unix(uint32_t id, const char *path, int backlog);
|
|
70
|
+
void net_listen_tls_unix(uint32_t id, const char *path, int backlog,
|
|
71
|
+
uint32_t secure_context_id);
|
|
72
|
+
|
|
73
|
+
#if !defined(__ANDROID__)
|
|
74
|
+
// Unix-only TLS functions (not available on Android)
|
|
75
|
+
void net_connect_unix_tls(uint32_t id, const char *path,
|
|
76
|
+
const char *server_name, int reject_unauthorized);
|
|
77
|
+
void net_connect_unix_tls_with_context(uint32_t id, const char *path,
|
|
78
|
+
const char *server_name,
|
|
79
|
+
int reject_unauthorized,
|
|
80
|
+
uint32_t secure_context_id);
|
|
81
|
+
#endif
|
|
47
82
|
|
|
48
83
|
// Server
|
|
49
84
|
uint32_t net_create_server();
|
|
50
85
|
void net_listen(uint32_t id, int port, int backlog, bool ipv6_only,
|
|
51
86
|
bool reuse_port);
|
|
87
|
+
void net_listen_tls(uint32_t id, int port, int backlog, bool ipv6_only,
|
|
88
|
+
bool reuse_port, uint32_t secure_context_id);
|
|
52
89
|
void net_server_close(uint32_t id);
|
|
53
90
|
void net_destroy_server(uint32_t id);
|
|
54
91
|
void net_server_set_max_connections(uint32_t id, int max_connections);
|
|
55
92
|
size_t net_get_server_local_address(uint32_t id, char *buf, size_t len);
|
|
93
|
+
uint32_t net_create_secure_context(const char *cert_pem, const char *key_pem,
|
|
94
|
+
const char *passphrase);
|
|
95
|
+
uint32_t net_secure_context_create();
|
|
96
|
+
void net_secure_context_add_ca(uint32_t sc_id, const char *ca_pem);
|
|
97
|
+
void net_secure_context_set_cert_key(uint32_t sc_id, const char *cert_pem,
|
|
98
|
+
const char *key_pem,
|
|
99
|
+
const char *passphrase);
|
|
100
|
+
void net_secure_context_add_context(uint32_t sc_id, const char *hostname,
|
|
101
|
+
const char *cert_pem, const char *key_pem,
|
|
102
|
+
const char *passphrase);
|
|
103
|
+
void net_secure_context_set_pfx(uint32_t sc_id, const uint8_t *data, size_t len,
|
|
104
|
+
const char *passphrase);
|
|
105
|
+
void net_secure_context_set_ocsp_response(uint32_t sc_id, const uint8_t *data,
|
|
106
|
+
size_t len);
|
|
56
107
|
/// Listen on an existing file descriptor (handle)
|
|
57
108
|
/// @param id Server ID
|
|
58
109
|
/// @param fd File descriptor of an already-bound TCP listener
|
|
59
110
|
/// @param backlog Listen backlog
|
|
60
111
|
void net_listen_handle(uint32_t id, int fd, int backlog);
|
|
61
112
|
|
|
113
|
+
// Session
|
|
114
|
+
bool net_is_session_reused(uint32_t id);
|
|
115
|
+
size_t net_get_session(uint32_t id, uint8_t *buf, size_t len);
|
|
116
|
+
void net_set_session(uint32_t id, const uint8_t *ticket, size_t ticket_len);
|
|
117
|
+
size_t net_server_get_ticket_keys(uint32_t id, uint8_t *buf, size_t len);
|
|
118
|
+
void net_server_set_ticket_keys(uint32_t id, const uint8_t *keys, size_t len);
|
|
119
|
+
|
|
120
|
+
// HTTP Parser
|
|
121
|
+
uint32_t net_http_parser_create(int mode);
|
|
122
|
+
int net_http_parser_feed(uint32_t id, const uint8_t *data, size_t len,
|
|
123
|
+
char *buf, size_t buf_len);
|
|
124
|
+
void net_http_parser_destroy(uint32_t id);
|
|
125
|
+
|
|
62
126
|
// Event Types
|
|
63
127
|
#define NET_EVENT_CONNECT 1
|
|
64
128
|
#define NET_EVENT_DATA 2
|
|
65
129
|
#define NET_EVENT_ERROR 3
|
|
66
130
|
#define NET_EVENT_CLOSE 4
|
|
67
131
|
#define NET_EVENT_CONNECTION 6
|
|
132
|
+
#define NET_EVENT_KEYLOG 10
|
|
133
|
+
#define NET_EVENT_OCSP 11
|
|
68
134
|
}
|
|
Binary file
|
package/ios/Frameworks/RustCNet.xcframework/ios-arm64_x86_64-simulator/RustCNet.framework/RustCNet
CHANGED
|
Binary file
|
package/lib/Net.nitro.d.ts
CHANGED
|
@@ -15,7 +15,9 @@ export declare enum NetSocketEvent {
|
|
|
15
15
|
DRAIN = 5,
|
|
16
16
|
TIMEOUT = 7,
|
|
17
17
|
LOOKUP = 8,
|
|
18
|
-
|
|
18
|
+
SESSION = 9,
|
|
19
|
+
KEYLOG = 10,
|
|
20
|
+
OCSP = 11
|
|
19
21
|
}
|
|
20
22
|
export interface NetSocketDriver extends HybridObject<{
|
|
21
23
|
ios: 'swift';
|
|
@@ -23,7 +25,21 @@ export interface NetSocketDriver extends HybridObject<{
|
|
|
23
25
|
}> {
|
|
24
26
|
readonly id: number;
|
|
25
27
|
connect(host: string, port: number): void;
|
|
28
|
+
connectTLS(host: string, port: number, serverName?: string, rejectUnauthorized?: boolean): void;
|
|
29
|
+
connectTLSWithContext(host: string, port: number, serverName?: string, rejectUnauthorized?: boolean, secureContextId?: number): void;
|
|
30
|
+
getAuthorizationError(): string | undefined;
|
|
31
|
+
getProtocol(): string | undefined;
|
|
32
|
+
getCipher(): string | undefined;
|
|
33
|
+
getALPN(): string | undefined;
|
|
34
|
+
getPeerCertificateJSON(): string | undefined;
|
|
35
|
+
getEphemeralKeyInfo(): string | undefined;
|
|
36
|
+
getSharedSigalgs(): string | undefined;
|
|
37
|
+
isSessionReused(): boolean;
|
|
38
|
+
getSession(): ArrayBuffer | undefined;
|
|
39
|
+
setSession(session: ArrayBuffer): void;
|
|
26
40
|
connectUnix(path: string): void;
|
|
41
|
+
connectUnixTLS(path: string, serverName?: string, rejectUnauthorized?: boolean): void;
|
|
42
|
+
connectUnixTLSWithContext(path: string, serverName?: string, rejectUnauthorized?: boolean, secureContextId?: number): void;
|
|
27
43
|
write(data: ArrayBuffer): void;
|
|
28
44
|
pause(): void;
|
|
29
45
|
resume(): void;
|
|
@@ -31,6 +47,9 @@ export interface NetSocketDriver extends HybridObject<{
|
|
|
31
47
|
setTimeout(timeout: number): void;
|
|
32
48
|
destroy(): void;
|
|
33
49
|
resetAndDestroy(): void;
|
|
50
|
+
enableKeylog(): void;
|
|
51
|
+
enableTrace(): void;
|
|
52
|
+
exportKeyingMaterial(length: number, label: string, context?: ArrayBuffer): ArrayBuffer | undefined;
|
|
34
53
|
setNoDelay(enable: boolean): void;
|
|
35
54
|
setKeepAlive(enable: boolean, delay: number): void;
|
|
36
55
|
getLocalAddress(): string;
|
|
@@ -49,7 +68,9 @@ export interface NetServerDriver extends HybridObject<{
|
|
|
49
68
|
}> {
|
|
50
69
|
onEvent: (event: number, data: ArrayBuffer) => void;
|
|
51
70
|
listen(port: number, backlog?: number, ipv6Only?: boolean, reusePort?: boolean): void;
|
|
71
|
+
listenTLS(port: number, secureContextId: number, backlog?: number, ipv6Only?: boolean, reusePort?: boolean): void;
|
|
52
72
|
listenUnix(path: string, backlog?: number): void;
|
|
73
|
+
listenTLSUnix(path: string, secureContextId: number, backlog?: number): void;
|
|
53
74
|
/**
|
|
54
75
|
* Listen on an existing file descriptor (handle)
|
|
55
76
|
* @param fd File descriptor of an already-bound TCP listener
|
|
@@ -60,6 +81,17 @@ export interface NetServerDriver extends HybridObject<{
|
|
|
60
81
|
maxConnections: number;
|
|
61
82
|
close(): void;
|
|
62
83
|
}
|
|
84
|
+
export interface HttpParser extends HybridObject<{
|
|
85
|
+
ios: 'swift';
|
|
86
|
+
android: 'kotlin';
|
|
87
|
+
}> {
|
|
88
|
+
/**
|
|
89
|
+
* Feed data to the parser
|
|
90
|
+
* @param data Raw byte data from the network
|
|
91
|
+
* @returns JSON string of the parsed message if complete, empty string if partial, or error message starting with 'ERROR:'
|
|
92
|
+
*/
|
|
93
|
+
feed(data: ArrayBuffer): string;
|
|
94
|
+
}
|
|
63
95
|
/**
|
|
64
96
|
* Runtime configuration for the network module
|
|
65
97
|
*/
|
|
@@ -69,6 +101,10 @@ export interface NetConfig {
|
|
|
69
101
|
* 0 = use CPU core count (default)
|
|
70
102
|
*/
|
|
71
103
|
workerThreads?: number;
|
|
104
|
+
/**
|
|
105
|
+
* Whether to enable verbose debug logging
|
|
106
|
+
*/
|
|
107
|
+
debug?: boolean;
|
|
72
108
|
}
|
|
73
109
|
export interface NetDriver extends HybridObject<{
|
|
74
110
|
ios: 'swift';
|
|
@@ -76,6 +112,15 @@ export interface NetDriver extends HybridObject<{
|
|
|
76
112
|
}> {
|
|
77
113
|
createSocket(id?: string): NetSocketDriver;
|
|
78
114
|
createServer(): NetServerDriver;
|
|
115
|
+
createHttpParser(mode: number): HttpParser;
|
|
116
|
+
createSecureContext(cert: string, key: string, passphrase?: string): number;
|
|
117
|
+
createEmptySecureContext(): number;
|
|
118
|
+
addCACertToSecureContext(scId: number, ca: string): void;
|
|
119
|
+
addContextToSecureContext(scId: number, hostname: string, cert: string, key: string, passphrase?: string): void;
|
|
120
|
+
setPFXToSecureContext(scId: number, pfx: ArrayBuffer, passphrase?: string): void;
|
|
121
|
+
setOCSPResponseToSecureContext(scId: number, ocsp: ArrayBuffer): void;
|
|
122
|
+
getTicketKeys(scId: number): ArrayBuffer | undefined;
|
|
123
|
+
setTicketKeys(scId: number, keys: ArrayBuffer): void;
|
|
79
124
|
/**
|
|
80
125
|
* Initialize the network module with custom configuration
|
|
81
126
|
* Must be called before any other network operations
|
package/lib/Net.nitro.js
CHANGED
|
@@ -10,7 +10,9 @@ var NetSocketEvent;
|
|
|
10
10
|
NetSocketEvent[NetSocketEvent["DRAIN"] = 5] = "DRAIN";
|
|
11
11
|
NetSocketEvent[NetSocketEvent["TIMEOUT"] = 7] = "TIMEOUT";
|
|
12
12
|
NetSocketEvent[NetSocketEvent["LOOKUP"] = 8] = "LOOKUP";
|
|
13
|
-
NetSocketEvent[NetSocketEvent["
|
|
13
|
+
NetSocketEvent[NetSocketEvent["SESSION"] = 9] = "SESSION";
|
|
14
|
+
NetSocketEvent[NetSocketEvent["KEYLOG"] = 10] = "KEYLOG";
|
|
15
|
+
NetSocketEvent[NetSocketEvent["OCSP"] = 11] = "OCSP";
|
|
14
16
|
})(NetSocketEvent || (exports.NetSocketEvent = NetSocketEvent = {}));
|
|
15
17
|
var NetServerEvent;
|
|
16
18
|
(function (NetServerEvent) {
|
package/lib/http.d.ts
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { Writable, Readable } from 'readable-stream';
|
|
2
|
+
import { EventEmitter } from 'eventemitter3';
|
|
3
|
+
import { Socket } from './index';
|
|
4
|
+
export declare const STATUS_CODES: Record<number, string>;
|
|
5
|
+
export declare const METHODS: string[];
|
|
6
|
+
export declare class IncomingMessage extends Readable {
|
|
7
|
+
httpVersion: string;
|
|
8
|
+
httpVersionMajor: number;
|
|
9
|
+
httpVersionMinor: number;
|
|
10
|
+
method?: string;
|
|
11
|
+
url?: string;
|
|
12
|
+
statusCode?: number;
|
|
13
|
+
statusMessage?: string;
|
|
14
|
+
headers: Record<string, string | string[]>;
|
|
15
|
+
rawHeaders: string[];
|
|
16
|
+
socket: Socket;
|
|
17
|
+
aborted: boolean;
|
|
18
|
+
complete: boolean;
|
|
19
|
+
trailers: Record<string, string>;
|
|
20
|
+
constructor(socket: Socket);
|
|
21
|
+
_read(): void;
|
|
22
|
+
setTimeout(msecs: number, callback?: () => void): this;
|
|
23
|
+
destroy(error?: Error): this;
|
|
24
|
+
setNoDelay(noDelay?: boolean): void;
|
|
25
|
+
setKeepAlive(enable?: boolean, initialDelay?: number): void;
|
|
26
|
+
}
|
|
27
|
+
export declare class OutgoingMessage extends Writable {
|
|
28
|
+
headersSent: boolean;
|
|
29
|
+
protected _headers: Record<string, any>;
|
|
30
|
+
protected _headerNames: Record<string, string>;
|
|
31
|
+
socket: Socket | null;
|
|
32
|
+
chunkedEncoding: boolean;
|
|
33
|
+
protected _hasBody: boolean;
|
|
34
|
+
protected _sendHeadersSent: boolean;
|
|
35
|
+
aborted: boolean;
|
|
36
|
+
protected _trailers: Record<string, string> | null;
|
|
37
|
+
constructor();
|
|
38
|
+
destroy(error?: Error): this;
|
|
39
|
+
setHeader(name: string, value: any): this;
|
|
40
|
+
getHeader(name: string): any;
|
|
41
|
+
removeHeader(name: string): void;
|
|
42
|
+
hasHeader(name: string): boolean;
|
|
43
|
+
getHeaderNames(): string[];
|
|
44
|
+
setTimeout(ms: number, callback?: () => void): this;
|
|
45
|
+
protected _renderHeaders(firstLine: string): string;
|
|
46
|
+
protected _sendHeaders(firstLine: string): void;
|
|
47
|
+
_write(chunk: any, encoding: string, callback: (error?: Error | null) => void): void;
|
|
48
|
+
write(chunk: any, encoding?: any, callback?: any): boolean;
|
|
49
|
+
_final(callback: (error?: Error | null) => void): void;
|
|
50
|
+
addTrailers(headers: Record<string, string>): void;
|
|
51
|
+
end(chunk?: any, encoding?: any, callback?: any): this;
|
|
52
|
+
setNoDelay(noDelay?: boolean): void;
|
|
53
|
+
setSocketKeepAlive(enable?: boolean, initialDelay?: number): void;
|
|
54
|
+
}
|
|
55
|
+
export declare class ServerResponse extends OutgoingMessage {
|
|
56
|
+
statusCode: number;
|
|
57
|
+
statusMessage?: string;
|
|
58
|
+
socket: Socket;
|
|
59
|
+
constructor(socket: Socket);
|
|
60
|
+
writeHead(statusCode: number, statusMessage?: string | Record<string, any>, headers?: Record<string, any>): this;
|
|
61
|
+
private _sendResponseHeaders;
|
|
62
|
+
_write(chunk: any, encoding: string, callback: (error?: Error | null) => void): void;
|
|
63
|
+
write(chunk: any, encoding?: any, callback?: any): boolean;
|
|
64
|
+
end(chunk?: any, encoding?: any, callback?: any): this;
|
|
65
|
+
}
|
|
66
|
+
export interface ServerOptions {
|
|
67
|
+
/**
|
|
68
|
+
* Optionally overrides all net.Server options.
|
|
69
|
+
*/
|
|
70
|
+
IncomingMessage?: typeof IncomingMessage;
|
|
71
|
+
ServerResponse?: typeof ServerResponse;
|
|
72
|
+
/**
|
|
73
|
+
* Keep-Alive header timeout in milliseconds.
|
|
74
|
+
*/
|
|
75
|
+
keepAliveTimeout?: number;
|
|
76
|
+
/**
|
|
77
|
+
* Request timeout in milliseconds.
|
|
78
|
+
*/
|
|
79
|
+
requestTimeout?: number;
|
|
80
|
+
/**
|
|
81
|
+
* Headers timeout in milliseconds.
|
|
82
|
+
*/
|
|
83
|
+
headersTimeout?: number;
|
|
84
|
+
/**
|
|
85
|
+
* Max header size in bytes.
|
|
86
|
+
*/
|
|
87
|
+
maxHeaderSize?: number;
|
|
88
|
+
/**
|
|
89
|
+
* If defined, sets the maximum number of requests socket can handle.
|
|
90
|
+
*/
|
|
91
|
+
maxRequestsPerSocket?: number;
|
|
92
|
+
}
|
|
93
|
+
export declare class Server extends EventEmitter {
|
|
94
|
+
protected _netServer: any;
|
|
95
|
+
protected _httpConnections: Set<Socket>;
|
|
96
|
+
maxHeaderSize: number;
|
|
97
|
+
maxRequestsPerSocket: number;
|
|
98
|
+
headersTimeout: number;
|
|
99
|
+
requestTimeout: number;
|
|
100
|
+
keepAliveTimeout: number;
|
|
101
|
+
constructor(options?: ServerOptions | ((req: IncomingMessage, res: ServerResponse) => void), requestListener?: (req: IncomingMessage, res: ServerResponse) => void);
|
|
102
|
+
protected _setupHttpConnection(socket: Socket): void;
|
|
103
|
+
listen(...args: any[]): this;
|
|
104
|
+
close(callback?: (err?: Error) => void): this;
|
|
105
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
106
|
+
address(): {
|
|
107
|
+
port: number;
|
|
108
|
+
family: string;
|
|
109
|
+
address: string;
|
|
110
|
+
} | null;
|
|
111
|
+
get listening(): boolean;
|
|
112
|
+
setTimeout(ms: number, callback?: () => void): this;
|
|
113
|
+
}
|
|
114
|
+
export interface AgentOptions {
|
|
115
|
+
keepAlive?: boolean;
|
|
116
|
+
keepAliveMsecs?: number;
|
|
117
|
+
maxSockets?: number;
|
|
118
|
+
maxTotalSockets?: number;
|
|
119
|
+
maxFreeSockets?: number;
|
|
120
|
+
scheduling?: 'fifo' | 'lifo';
|
|
121
|
+
timeout?: number;
|
|
122
|
+
maxCachedSessions?: number;
|
|
123
|
+
}
|
|
124
|
+
export declare class Agent extends EventEmitter {
|
|
125
|
+
maxSockets: number;
|
|
126
|
+
maxTotalSockets: number;
|
|
127
|
+
maxFreeSockets: number;
|
|
128
|
+
keepAlive: boolean;
|
|
129
|
+
keepAliveMsecs: number;
|
|
130
|
+
maxCachedSessions: number;
|
|
131
|
+
scheduling: 'fifo' | 'lifo';
|
|
132
|
+
requests: Record<string, ClientRequest[]>;
|
|
133
|
+
sockets: Record<string, Socket[]>;
|
|
134
|
+
freeSockets: Record<string, Socket[]>;
|
|
135
|
+
private _totalSockets;
|
|
136
|
+
proxy: string | null;
|
|
137
|
+
/**
|
|
138
|
+
* Gets the proxy URL for the given request options.
|
|
139
|
+
* Checks HTTP_PROXY, HTTPS_PROXY, and NO_PROXY environment variables.
|
|
140
|
+
*
|
|
141
|
+
* @param options Request options to determine if proxy should be used
|
|
142
|
+
* @returns Proxy URL or null if no proxy should be used
|
|
143
|
+
*/
|
|
144
|
+
protected getProxy(options: RequestOptions): string | null;
|
|
145
|
+
constructor(options?: AgentOptions);
|
|
146
|
+
getName(options: RequestOptions): string;
|
|
147
|
+
addRequest(req: ClientRequest, options: RequestOptions): void;
|
|
148
|
+
createConnection(options: RequestOptions, callback: (err: Error | null, socket: Socket) => void): Socket;
|
|
149
|
+
releaseSocket(socket: Socket, options: RequestOptions): void;
|
|
150
|
+
keepSocketAlive(_socket: Socket): boolean;
|
|
151
|
+
reuseSocket(socket: Socket, req: ClientRequest): void;
|
|
152
|
+
private _removeSocket;
|
|
153
|
+
destroy(): void;
|
|
154
|
+
}
|
|
155
|
+
export declare const globalAgent: Agent;
|
|
156
|
+
export interface RequestOptions {
|
|
157
|
+
protocol?: string;
|
|
158
|
+
host?: string;
|
|
159
|
+
hostname?: string;
|
|
160
|
+
family?: number;
|
|
161
|
+
port?: number;
|
|
162
|
+
localAddress?: string;
|
|
163
|
+
socketPath?: string;
|
|
164
|
+
method?: string;
|
|
165
|
+
path?: string;
|
|
166
|
+
headers?: Record<string, any>;
|
|
167
|
+
auth?: string;
|
|
168
|
+
agent?: Agent | boolean;
|
|
169
|
+
timeout?: number;
|
|
170
|
+
rejectUnauthorized?: boolean;
|
|
171
|
+
}
|
|
172
|
+
export declare class ClientRequest extends OutgoingMessage {
|
|
173
|
+
method: string;
|
|
174
|
+
path: string;
|
|
175
|
+
host: string;
|
|
176
|
+
private _res?;
|
|
177
|
+
private _options;
|
|
178
|
+
private _connected;
|
|
179
|
+
private _pendingWrites;
|
|
180
|
+
private _ended;
|
|
181
|
+
private _expectContinue;
|
|
182
|
+
private _continueReceived;
|
|
183
|
+
constructor(options: RequestOptions, callback?: (res: IncomingMessage) => void);
|
|
184
|
+
/** @internal */
|
|
185
|
+
onSocket(socket: Socket | null): void;
|
|
186
|
+
private _connect;
|
|
187
|
+
private _attachSocketListeners;
|
|
188
|
+
private _socketCleanup?;
|
|
189
|
+
private _cleanupSocket;
|
|
190
|
+
private _finishResponse;
|
|
191
|
+
private _flushPendingWrites;
|
|
192
|
+
private _finishRequest;
|
|
193
|
+
private _sendRequest;
|
|
194
|
+
_write(chunk: any, encoding: string, callback: (error?: Error | null) => void): void;
|
|
195
|
+
write(chunk: any, encoding?: any, callback?: any): boolean;
|
|
196
|
+
end(chunk?: any, encoding?: any, callback?: any): this;
|
|
197
|
+
abort(): void;
|
|
198
|
+
flushHeaders(): void;
|
|
199
|
+
}
|
|
200
|
+
export declare function createServer(requestListener?: (req: IncomingMessage, res: ServerResponse) => void): Server;
|
|
201
|
+
export declare function createServer(options: ServerOptions, requestListener?: (req: IncomingMessage, res: ServerResponse) => void): Server;
|
|
202
|
+
export declare function request(urlOrOptions: string | URL | RequestOptions, optionsOrCallback?: RequestOptions | ((res: IncomingMessage) => void), callback?: (res: IncomingMessage) => void): ClientRequest;
|
|
203
|
+
export declare function get(urlOrOptions: string | URL | RequestOptions, optionsOrCallback?: RequestOptions | ((res: IncomingMessage) => void), callback?: (res: IncomingMessage) => void): ClientRequest;
|