react-native-nitro-net 0.5.1 → 0.5.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/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/HybridNetDriver.hpp +17 -0
- package/cpp/NetManager.hpp +40 -69
- 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/http.d.ts +3 -0
- package/lib/http.d.ts.map +1 -1
- package/lib/http.js +182 -61
- package/lib/net.d.ts +2 -3
- package/lib/net.d.ts.map +1 -1
- package/lib/net.js +61 -15
- package/package.json +2 -1
- package/react-native-nitro-net.podspec +2 -2
- package/src/http.ts +183 -59
- package/src/net.ts +62 -18
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/cpp/HybridNetDriver.hpp
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
#include "HybridNetSocketDriver.hpp"
|
|
8
8
|
#include "NetManager.hpp"
|
|
9
9
|
#include <NitroModules/ArrayBuffer.hpp>
|
|
10
|
+
#include <jsi/jsi.h>
|
|
10
11
|
#include <optional>
|
|
11
12
|
#include <string>
|
|
12
13
|
|
|
@@ -20,6 +21,22 @@ class HybridNetDriver : public HybridNetDriverSpec {
|
|
|
20
21
|
public:
|
|
21
22
|
HybridNetDriver() : HybridObject(TAG) {}
|
|
22
23
|
|
|
24
|
+
jsi::Value installDispatcher(jsi::Runtime &runtime, const jsi::Value &,
|
|
25
|
+
const jsi::Value *, size_t) {
|
|
26
|
+
auto dispatcher =
|
|
27
|
+
margelo::nitro::Dispatcher::getRuntimeGlobalDispatcher(runtime);
|
|
28
|
+
NetManager::shared().setDispatcher(dispatcher);
|
|
29
|
+
return jsi::Value::undefined();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
void loadHybridMethods() override {
|
|
33
|
+
HybridNetDriverSpec::loadHybridMethods();
|
|
34
|
+
registerHybrids(this, [](Prototype &prototype) {
|
|
35
|
+
prototype.registerRawHybridMethod("installDispatcher", 0,
|
|
36
|
+
&HybridNetDriver::installDispatcher);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
23
40
|
std::shared_ptr<HybridNetSocketDriverSpec>
|
|
24
41
|
createSocket(const std::optional<std::string> &id) override {
|
|
25
42
|
if (id.has_value()) {
|
package/cpp/NetManager.hpp
CHANGED
|
@@ -28,6 +28,9 @@
|
|
|
28
28
|
printf("\n")
|
|
29
29
|
#endif
|
|
30
30
|
|
|
31
|
+
#include <NitroModules/Dispatcher.hpp>
|
|
32
|
+
#include <NitroModules/NitroLogger.hpp>
|
|
33
|
+
|
|
31
34
|
namespace margelo::nitro::net {
|
|
32
35
|
|
|
33
36
|
class NetManager {
|
|
@@ -45,15 +48,18 @@ public:
|
|
|
45
48
|
initializeRuntime(0); // 0 = use default (CPU core count)
|
|
46
49
|
}
|
|
47
50
|
|
|
51
|
+
void setDispatcher(std::shared_ptr<margelo::nitro::Dispatcher> dispatcher) {
|
|
52
|
+
LOGI("NetManager: Dispatcher installed.");
|
|
53
|
+
_dispatcher = dispatcher;
|
|
54
|
+
}
|
|
55
|
+
|
|
48
56
|
/// Initialize with custom worker thread count
|
|
49
|
-
/// Must be called before any other operations, or the config will be ignored
|
|
50
57
|
void initWithConfig(uint32_t workerThreads) {
|
|
51
58
|
if (!_initialized) {
|
|
52
59
|
LOGI("Initializing NetManager with %u worker threads...", workerThreads);
|
|
53
60
|
initializeRuntime(workerThreads);
|
|
54
61
|
} else {
|
|
55
|
-
LOGW("NetManager already initialized, config ignored.
|
|
56
|
-
"initWithConfig before any socket/server operations.");
|
|
62
|
+
LOGW("NetManager already initialized, config ignored.");
|
|
57
63
|
}
|
|
58
64
|
}
|
|
59
65
|
|
|
@@ -63,26 +69,21 @@ private:
|
|
|
63
69
|
return;
|
|
64
70
|
_initialized = true;
|
|
65
71
|
|
|
66
|
-
|
|
67
|
-
net_init_with_config(
|
|
68
|
-
[](uint32_t id, int event_type, const uint8_t *data, size_t len,
|
|
72
|
+
auto callback = [](uint32_t id, int event_type, const uint8_t *data, size_t len,
|
|
69
73
|
void *context) {
|
|
70
74
|
auto mgr = static_cast<NetManager *>(context);
|
|
71
75
|
mgr->dispatch(id, event_type, data, len);
|
|
72
|
-
}
|
|
73
|
-
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
if (workerThreads > 0) {
|
|
79
|
+
net_init_with_config(callback, this, workerThreads);
|
|
74
80
|
} else {
|
|
75
|
-
net_init(
|
|
76
|
-
[](uint32_t id, int event_type, const uint8_t *data, size_t len,
|
|
77
|
-
void *context) {
|
|
78
|
-
auto mgr = static_cast<NetManager *>(context);
|
|
79
|
-
mgr->dispatch(id, event_type, data, len);
|
|
80
|
-
},
|
|
81
|
-
this);
|
|
81
|
+
net_init(callback, this);
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
bool _initialized = false;
|
|
86
|
+
std::shared_ptr<margelo::nitro::Dispatcher> _dispatcher;
|
|
86
87
|
|
|
87
88
|
public:
|
|
88
89
|
void registerHandler(uint32_t id, EventHandler handler) {
|
|
@@ -99,63 +100,33 @@ public:
|
|
|
99
100
|
|
|
100
101
|
private:
|
|
101
102
|
void dispatch(uint32_t id, int eventType, const uint8_t *data, size_t len) {
|
|
102
|
-
//
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
eventName = "CONNECT";
|
|
107
|
-
break;
|
|
108
|
-
case NET_EVENT_DATA:
|
|
109
|
-
eventName = "DATA";
|
|
110
|
-
break;
|
|
111
|
-
case NET_EVENT_ERROR:
|
|
112
|
-
eventName = "ERROR";
|
|
113
|
-
break;
|
|
114
|
-
case NET_EVENT_CLOSE:
|
|
115
|
-
eventName = "CLOSE";
|
|
116
|
-
break;
|
|
117
|
-
case NET_EVENT_WRITTEN:
|
|
118
|
-
eventName = "DRAIN";
|
|
119
|
-
break;
|
|
120
|
-
case NET_EVENT_CONNECTION:
|
|
121
|
-
eventName = "CONNECTION";
|
|
122
|
-
break;
|
|
123
|
-
case NET_EVENT_TIMEOUT:
|
|
124
|
-
eventName = "TIMEOUT";
|
|
125
|
-
break;
|
|
126
|
-
case NET_EVENT_LOOKUP:
|
|
127
|
-
eventName = "LOOKUP";
|
|
128
|
-
break;
|
|
129
|
-
case NET_EVENT_SESSION:
|
|
130
|
-
eventName = "SESSION";
|
|
131
|
-
break;
|
|
132
|
-
case NET_EVENT_KEYLOG:
|
|
133
|
-
eventName = "KEYLOG";
|
|
134
|
-
break;
|
|
135
|
-
case NET_EVENT_OCSP:
|
|
136
|
-
eventName = "OCSP";
|
|
137
|
-
break;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
LOGI("dispatch: id=%u, event=%s(%d), len=%zu", id, eventName, eventType,
|
|
141
|
-
len);
|
|
142
|
-
|
|
143
|
-
// Copy handler outside of lock to avoid deadlock
|
|
144
|
-
// (handler may call unregisterHandler which needs unique_lock)
|
|
145
|
-
EventHandler handler;
|
|
146
|
-
{
|
|
147
|
-
std::shared_lock lock(_mutex);
|
|
148
|
-
auto it = _handlers.find(id);
|
|
149
|
-
if (it != _handlers.end()) {
|
|
150
|
-
handler = it->second;
|
|
151
|
-
}
|
|
103
|
+
// 1. Prepare data (copy if needed for async)
|
|
104
|
+
std::vector<uint8_t> buffer;
|
|
105
|
+
if (data && len > 0) {
|
|
106
|
+
buffer.assign(data, data + len);
|
|
152
107
|
}
|
|
153
108
|
|
|
154
|
-
//
|
|
155
|
-
|
|
156
|
-
|
|
109
|
+
// 2. Define the actual dispatch logic
|
|
110
|
+
auto doDispatch = [this, id, eventType, buffer = std::move(buffer)]() {
|
|
111
|
+
EventHandler handler;
|
|
112
|
+
{
|
|
113
|
+
std::shared_lock lock(_mutex);
|
|
114
|
+
auto it = _handlers.find(id);
|
|
115
|
+
if (it != _handlers.end()) {
|
|
116
|
+
handler = it->second;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (handler) {
|
|
121
|
+
handler(eventType, buffer.data(), buffer.size());
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// 3. Dispatch either via JS Dispatcher (Async) or immediately (Sync fallback)
|
|
126
|
+
if (_dispatcher) {
|
|
127
|
+
_dispatcher->runAsync(std::move(doDispatch));
|
|
157
128
|
} else {
|
|
158
|
-
|
|
129
|
+
doDispatch();
|
|
159
130
|
}
|
|
160
131
|
}
|
|
161
132
|
|
|
Binary file
|
package/ios/Frameworks/RustCNet.xcframework/ios-arm64_x86_64-simulator/RustCNet.framework/RustCNet
CHANGED
|
Binary file
|
package/lib/http.d.ts
CHANGED
|
@@ -180,6 +180,8 @@ export declare class ClientRequest extends OutgoingMessage {
|
|
|
180
180
|
private _ended;
|
|
181
181
|
private _expectContinue;
|
|
182
182
|
private _continueReceived;
|
|
183
|
+
private _getChunkByteLength;
|
|
184
|
+
private _getPendingBodyLength;
|
|
183
185
|
constructor(options: RequestOptions, callback?: (res: IncomingMessage) => void);
|
|
184
186
|
/** @internal */
|
|
185
187
|
onSocket(socket: Socket | null): void;
|
|
@@ -188,6 +190,7 @@ export declare class ClientRequest extends OutgoingMessage {
|
|
|
188
190
|
private _socketCleanup?;
|
|
189
191
|
private _cleanupSocket;
|
|
190
192
|
private _finishResponse;
|
|
193
|
+
private _isFlushing;
|
|
191
194
|
private _flushPendingWrites;
|
|
192
195
|
private _finishRequest;
|
|
193
196
|
private _sendRequest;
|
package/lib/http.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,E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 -91,7 +91,14 @@ export class IncomingMessage extends Readable {
|
|
|
91
91
|
this.socket = socket;
|
|
92
92
|
}
|
|
93
93
|
_read() {
|
|
94
|
-
|
|
94
|
+
// Server-side: socket is kept flowing by _setupHttpConnection.
|
|
95
|
+
// Calling socket.resume() here is the correct Node.js backpressure pattern
|
|
96
|
+
// but only when socket is the actual data source (client-side IncomingMessage).
|
|
97
|
+
// For server-side req, body bytes come via parser→push(), not socket directly.
|
|
98
|
+
// Still call resume() to unblock if paused by backpressure, but guard it.
|
|
99
|
+
if (this.socket && !this.socket._destroyed) {
|
|
100
|
+
this.socket.resume();
|
|
101
|
+
}
|
|
95
102
|
}
|
|
96
103
|
setTimeout(msecs, callback) {
|
|
97
104
|
this.socket.setTimeout(msecs, callback);
|
|
@@ -260,8 +267,16 @@ export class OutgoingMessage extends Writable {
|
|
|
260
267
|
this._trailers = headers;
|
|
261
268
|
}
|
|
262
269
|
end(chunk, encoding, callback) {
|
|
263
|
-
|
|
264
|
-
|
|
270
|
+
if (typeof chunk === 'function') {
|
|
271
|
+
callback = chunk;
|
|
272
|
+
chunk = null;
|
|
273
|
+
encoding = null;
|
|
274
|
+
}
|
|
275
|
+
else if (typeof encoding === 'function') {
|
|
276
|
+
callback = encoding;
|
|
277
|
+
encoding = null;
|
|
278
|
+
}
|
|
279
|
+
if (chunk != null) {
|
|
265
280
|
this.write(chunk, encoding);
|
|
266
281
|
}
|
|
267
282
|
super.end(callback);
|
|
@@ -324,27 +339,31 @@ export class ServerResponse extends OutgoingMessage {
|
|
|
324
339
|
return super.write(chunk, encoding, callback);
|
|
325
340
|
}
|
|
326
341
|
end(chunk, encoding, callback) {
|
|
342
|
+
if (typeof chunk === 'function') {
|
|
343
|
+
callback = chunk;
|
|
344
|
+
chunk = null;
|
|
345
|
+
encoding = null;
|
|
346
|
+
}
|
|
347
|
+
else if (typeof encoding === 'function') {
|
|
348
|
+
callback = encoding;
|
|
349
|
+
encoding = null;
|
|
350
|
+
}
|
|
327
351
|
if (!this.headersSent) {
|
|
328
352
|
// If we have a single chunk and no headers sent yet, we can add Content-Length
|
|
329
353
|
// to avoid chunked encoding for simple responses.
|
|
330
|
-
if (chunk) {
|
|
331
|
-
const len = typeof chunk === 'string' ? Buffer.byteLength(chunk, encoding) : chunk.length;
|
|
354
|
+
if (chunk != null) {
|
|
355
|
+
const len = typeof chunk === 'string' ? Buffer.byteLength(chunk, encoding || undefined) : chunk.length;
|
|
332
356
|
this.setHeader('Content-Length', len);
|
|
333
357
|
}
|
|
334
|
-
else {
|
|
358
|
+
else if (!this.hasHeader('Transfer-Encoding')) {
|
|
335
359
|
this.setHeader('Content-Length', 0);
|
|
336
360
|
}
|
|
337
361
|
this._sendResponseHeaders();
|
|
338
362
|
}
|
|
339
|
-
if (
|
|
340
|
-
|
|
341
|
-
}
|
|
342
|
-
else if (chunk == null) {
|
|
343
|
-
super.end(callback);
|
|
344
|
-
}
|
|
345
|
-
else {
|
|
346
|
-
super.end(chunk, encoding, callback);
|
|
363
|
+
if (chunk != null) {
|
|
364
|
+
this.write(chunk, encoding);
|
|
347
365
|
}
|
|
366
|
+
super.end(callback);
|
|
348
367
|
return this;
|
|
349
368
|
}
|
|
350
369
|
}
|
|
@@ -481,15 +500,55 @@ export class Server extends EventEmitter {
|
|
|
481
500
|
this.emit('request', req, res);
|
|
482
501
|
}
|
|
483
502
|
}
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
503
|
+
// Push body/EOF into IncomingMessage.
|
|
504
|
+
// CRITICAL: When headers and body arrive in the same TCP packet
|
|
505
|
+
// (parsed.is_headers && body present), the user's 'request' handler
|
|
506
|
+
// has just been called synchronously above. The readable-stream
|
|
507
|
+
// library schedules its internal resume/flow via process.nextTick.
|
|
508
|
+
// If we push() synchronously here, the data lands in the buffer
|
|
509
|
+
// *before* the Readable enters flowing mode, and since no further
|
|
510
|
+
// socket data events will arrive, the flow() loop never drains it.
|
|
511
|
+
// Solution: always defer body/EOF push via process.nextTick so the
|
|
512
|
+
// Readable has a chance to enter flowing mode first.
|
|
513
|
+
const _bodyToPush = req && parsed.body && parsed.body.length > 0
|
|
514
|
+
? Buffer.from(parsed.body) : null;
|
|
515
|
+
const _isComplete = !!(req && parsed.complete);
|
|
516
|
+
const _trailers = parsed.trailers;
|
|
517
|
+
const _reqRef = req;
|
|
518
|
+
// Diagnostic: log body delivery state (requires debug mode)
|
|
519
|
+
debugLog(`[Server] handleParsedResult: is_headers=${parsed.is_headers}, ` +
|
|
520
|
+
`bodyLen=${_bodyToPush?.length ?? 0}, complete=${_isComplete}, ` +
|
|
521
|
+
`req.readableFlowing=${_reqRef?._readableState?.flowing}`);
|
|
522
|
+
if (_bodyToPush !== null || _isComplete) {
|
|
523
|
+
if (parsed.is_headers) {
|
|
524
|
+
// Same-packet case: defer to give Readable time to enter flowing mode
|
|
525
|
+
debugLog(`[Server] Deferring body/EOF push via setImmediate (same-packet)`);
|
|
526
|
+
setImmediate(() => {
|
|
527
|
+
if (!_reqRef)
|
|
528
|
+
return;
|
|
529
|
+
debugLog(`[Server] setImmediate: pushing body=${_bodyToPush?.length ?? 0}, EOF=${_isComplete}`);
|
|
530
|
+
if (_bodyToPush)
|
|
531
|
+
_reqRef.push(_bodyToPush);
|
|
532
|
+
if (_isComplete) {
|
|
533
|
+
_reqRef.complete = true;
|
|
534
|
+
if (_trailers)
|
|
535
|
+
_reqRef.trailers = _trailers;
|
|
536
|
+
_reqRef.push(null);
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
else {
|
|
541
|
+
// Subsequent-packet case: push immediately
|
|
542
|
+
debugLog(`[Server] Pushing body/EOF immediately (subsequent-packet)`);
|
|
543
|
+
if (_bodyToPush)
|
|
544
|
+
_reqRef.push(_bodyToPush);
|
|
545
|
+
if (_isComplete) {
|
|
546
|
+
_reqRef.complete = true;
|
|
547
|
+
if (_trailers)
|
|
548
|
+
_reqRef.trailers = _trailers;
|
|
549
|
+
_reqRef.push(null);
|
|
550
|
+
}
|
|
491
551
|
}
|
|
492
|
-
req.push(null);
|
|
493
552
|
}
|
|
494
553
|
// For Keep-Alive, try to parse remaining buffer in case of pipelining
|
|
495
554
|
if (parsed.complete && !req) {
|
|
@@ -816,6 +875,24 @@ export class Agent extends EventEmitter {
|
|
|
816
875
|
}
|
|
817
876
|
export const globalAgent = new Agent();
|
|
818
877
|
export class ClientRequest extends OutgoingMessage {
|
|
878
|
+
_getChunkByteLength(chunk, encoding) {
|
|
879
|
+
if (chunk == null)
|
|
880
|
+
return 0;
|
|
881
|
+
const normalizedEncoding = typeof encoding === 'string' ? encoding : undefined;
|
|
882
|
+
if (typeof chunk === 'string') {
|
|
883
|
+
return Buffer.byteLength(chunk, normalizedEncoding);
|
|
884
|
+
}
|
|
885
|
+
if (typeof chunk.length === 'number') {
|
|
886
|
+
return chunk.length;
|
|
887
|
+
}
|
|
888
|
+
const buffer = Buffer.from(chunk, normalizedEncoding);
|
|
889
|
+
return buffer.length;
|
|
890
|
+
}
|
|
891
|
+
_getPendingBodyLength() {
|
|
892
|
+
return this._pendingWrites.reduce((total, pending) => {
|
|
893
|
+
return total + this._getChunkByteLength(pending.chunk, pending.encoding);
|
|
894
|
+
}, 0);
|
|
895
|
+
}
|
|
819
896
|
constructor(options, callback) {
|
|
820
897
|
super();
|
|
821
898
|
this._connected = false;
|
|
@@ -823,6 +900,7 @@ export class ClientRequest extends OutgoingMessage {
|
|
|
823
900
|
this._ended = false;
|
|
824
901
|
this._expectContinue = false;
|
|
825
902
|
this._continueReceived = false;
|
|
903
|
+
this._isFlushing = false;
|
|
826
904
|
this._options = options;
|
|
827
905
|
this.method = options.method || 'GET';
|
|
828
906
|
this.path = options.path || '/';
|
|
@@ -859,9 +937,10 @@ export class ClientRequest extends OutgoingMessage {
|
|
|
859
937
|
this.socket = socket;
|
|
860
938
|
this._connected = true;
|
|
861
939
|
this.emit('socket', this.socket);
|
|
862
|
-
//
|
|
863
|
-
|
|
940
|
+
// IMPORTANT: attach response listeners BEFORE flushing writes.
|
|
941
|
+
// If we flush first, the server may respond before we have a data listener.
|
|
864
942
|
this._attachSocketListeners();
|
|
943
|
+
this._flushPendingWrites();
|
|
865
944
|
}
|
|
866
945
|
else {
|
|
867
946
|
this._connect();
|
|
@@ -875,15 +954,18 @@ export class ClientRequest extends OutgoingMessage {
|
|
|
875
954
|
this.emit('error', err);
|
|
876
955
|
return;
|
|
877
956
|
}
|
|
878
|
-
debugLog(`ClientRequest._connect: Socket connected
|
|
879
|
-
debugLog(`[HTTP] _connect: Socket connected!`);
|
|
957
|
+
debugLog(`ClientRequest._connect: Socket connected!`);
|
|
880
958
|
this.socket = socket;
|
|
881
959
|
this._connected = true;
|
|
882
960
|
this.emit('socket', this.socket);
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
this._flushPendingWrites();
|
|
961
|
+
// IMPORTANT: attach response listeners BEFORE flushing writes.
|
|
962
|
+
// If we flush first, the server may respond before we have a data listener.
|
|
886
963
|
this._attachSocketListeners();
|
|
964
|
+
// _flushPendingWrites() internally calls _sendRequest() if headers not sent yet.
|
|
965
|
+
// Do NOT call _sendRequest() separately here — _flushPendingWrites() needs to
|
|
966
|
+
// inspect headersSent and _pendingWrites together so it can set Content-Length
|
|
967
|
+
// before sending headers (to avoid chunked encoding when body is already known).
|
|
968
|
+
this._flushPendingWrites();
|
|
887
969
|
};
|
|
888
970
|
this.socket = agent.createConnection(this._options, connectCallback);
|
|
889
971
|
}
|
|
@@ -1015,27 +1097,59 @@ export class ClientRequest extends OutgoingMessage {
|
|
|
1015
1097
|
this.emit('close');
|
|
1016
1098
|
}
|
|
1017
1099
|
_flushPendingWrites() {
|
|
1018
|
-
if (!this.socket)
|
|
1019
|
-
return;
|
|
1020
|
-
if (!this.headersSent)
|
|
1021
|
-
this._sendRequest();
|
|
1022
|
-
// If we are waiting for 100-continue, don't flush yet
|
|
1023
|
-
if (this._expectContinue && !this._continueReceived) {
|
|
1100
|
+
if (!this.socket || this._isFlushing)
|
|
1024
1101
|
return;
|
|
1102
|
+
this._isFlushing = true;
|
|
1103
|
+
try {
|
|
1104
|
+
if (!this.headersSent) {
|
|
1105
|
+
// KEY FIX: When all body data is already queued AND the request is ending,
|
|
1106
|
+
// we can calculate the exact Content-Length and avoid chunked encoding.
|
|
1107
|
+
//
|
|
1108
|
+
// Why this matters: without Content-Length, the request is sent with
|
|
1109
|
+
// Transfer-Encoding: chunked. The Rust HTTP parser on the server side
|
|
1110
|
+
// stores chunked body bytes in its internal buffer after parsing headers,
|
|
1111
|
+
// but calling parser.feed(empty_buffer) to drain those bytes does NOT work
|
|
1112
|
+
// — the drain call returns empty metadata and the body is permanently lost.
|
|
1113
|
+
//
|
|
1114
|
+
// By setting Content-Length here (when we have all the data), the body is
|
|
1115
|
+
// sent as raw bytes. The server parser simply reads N bytes and marks the
|
|
1116
|
+
// request complete — no chunked framing, no drain issues.
|
|
1117
|
+
if (this._ended
|
|
1118
|
+
&& !this.hasHeader('Content-Length')
|
|
1119
|
+
&& !this.hasHeader('Transfer-Encoding')
|
|
1120
|
+
&& this._pendingWrites.length > 0) {
|
|
1121
|
+
const totalLen = this._getPendingBodyLength();
|
|
1122
|
+
this.setHeader('Content-Length', totalLen);
|
|
1123
|
+
}
|
|
1124
|
+
this._sendRequest();
|
|
1125
|
+
}
|
|
1126
|
+
// If we are waiting for 100-continue, don't flush yet
|
|
1127
|
+
if (this._expectContinue && !this._continueReceived) {
|
|
1128
|
+
return;
|
|
1129
|
+
}
|
|
1130
|
+
// Keep draining the queue as long as it has items
|
|
1131
|
+
// This handles writes that might happen while we are flushing (e.g. from callbacks)
|
|
1132
|
+
while (this._pendingWrites.length > 0) {
|
|
1133
|
+
const writes = this._pendingWrites;
|
|
1134
|
+
this._pendingWrites = [];
|
|
1135
|
+
for (const pending of writes) {
|
|
1136
|
+
// Call super._write (OutgoingMessage._write) directly
|
|
1137
|
+
super._write(pending.chunk, pending.encoding, pending.callback);
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
if (this._ended) {
|
|
1141
|
+
super.end();
|
|
1142
|
+
}
|
|
1025
1143
|
}
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
for (const pending of writes) {
|
|
1029
|
-
this._write(pending.chunk, pending.encoding, pending.callback);
|
|
1030
|
-
}
|
|
1031
|
-
if (this._ended) {
|
|
1032
|
-
this._finishRequest();
|
|
1144
|
+
finally {
|
|
1145
|
+
this._isFlushing = false;
|
|
1033
1146
|
}
|
|
1034
1147
|
}
|
|
1148
|
+
// Simplified _finishRequest - not needed as much if we call super.end() directly
|
|
1035
1149
|
_finishRequest() {
|
|
1036
|
-
if (
|
|
1037
|
-
|
|
1038
|
-
|
|
1150
|
+
if (this._connected && this._pendingWrites.length === 0) {
|
|
1151
|
+
super.end();
|
|
1152
|
+
}
|
|
1039
1153
|
}
|
|
1040
1154
|
_sendRequest() {
|
|
1041
1155
|
debugLog(`ClientRequest._sendRequest: headersSent=${this.headersSent}, socket=${!!this.socket}`);
|
|
@@ -1050,7 +1164,7 @@ export class ClientRequest extends OutgoingMessage {
|
|
|
1050
1164
|
}
|
|
1051
1165
|
_write(chunk, encoding, callback) {
|
|
1052
1166
|
this._hasBody = true;
|
|
1053
|
-
if (!this._connected) {
|
|
1167
|
+
if (!this._connected || this._isFlushing) {
|
|
1054
1168
|
this._pendingWrites.push({ chunk, encoding, callback });
|
|
1055
1169
|
return;
|
|
1056
1170
|
}
|
|
@@ -1060,39 +1174,46 @@ export class ClientRequest extends OutgoingMessage {
|
|
|
1060
1174
|
}
|
|
1061
1175
|
write(chunk, encoding, callback) {
|
|
1062
1176
|
this._hasBody = true;
|
|
1063
|
-
|
|
1177
|
+
// If not connected OR currently flushing, enqueue to preserve order
|
|
1178
|
+
if (!this._connected || this._isFlushing) {
|
|
1064
1179
|
this._pendingWrites.push({ chunk, encoding, callback });
|
|
1065
1180
|
return true;
|
|
1066
1181
|
}
|
|
1067
|
-
if (!this.headersSent)
|
|
1068
|
-
this._sendRequest();
|
|
1069
1182
|
return super.write(chunk, encoding, callback);
|
|
1070
1183
|
}
|
|
1071
1184
|
end(chunk, encoding, callback) {
|
|
1072
|
-
|
|
1073
|
-
|
|
1185
|
+
if (typeof chunk === 'function') {
|
|
1186
|
+
callback = chunk;
|
|
1187
|
+
chunk = null;
|
|
1188
|
+
encoding = null;
|
|
1189
|
+
}
|
|
1190
|
+
else if (typeof encoding === 'function') {
|
|
1191
|
+
callback = encoding;
|
|
1192
|
+
encoding = null;
|
|
1193
|
+
}
|
|
1194
|
+
debugLog(`ClientRequest.end() called, connected=${this._connected}, chunk=${!!chunk}`);
|
|
1195
|
+
if (chunk != null) {
|
|
1074
1196
|
this._hasBody = true;
|
|
1075
1197
|
if (!this.headersSent && !this.hasHeader('Content-Length')) {
|
|
1076
|
-
const len =
|
|
1198
|
+
const len = this._getPendingBodyLength() + this._getChunkByteLength(chunk, encoding);
|
|
1077
1199
|
this.setHeader('Content-Length', len);
|
|
1078
1200
|
}
|
|
1201
|
+
// Use this.write to handle pending queue if not connected
|
|
1079
1202
|
this.write(chunk, encoding);
|
|
1080
1203
|
}
|
|
1081
1204
|
this._ended = true;
|
|
1082
|
-
// If connected, we can send request and end immediately
|
|
1083
1205
|
if (this._connected) {
|
|
1084
|
-
if
|
|
1085
|
-
|
|
1206
|
+
// Only end if the queue is empty. _flushPendingWrites will handle it otherwise.
|
|
1207
|
+
if (this._pendingWrites.length === 0) {
|
|
1208
|
+
super.end(callback);
|
|
1209
|
+
}
|
|
1210
|
+
else if (callback) {
|
|
1211
|
+
this.once('finish', callback);
|
|
1086
1212
|
}
|
|
1087
|
-
// Call super.end only when connected
|
|
1088
|
-
super.end(callback);
|
|
1089
1213
|
}
|
|
1090
1214
|
else {
|
|
1091
|
-
|
|
1092
|
-
// Store callback if provided
|
|
1093
|
-
if (callback) {
|
|
1215
|
+
if (callback)
|
|
1094
1216
|
this.once('finish', callback);
|
|
1095
|
-
}
|
|
1096
1217
|
}
|
|
1097
1218
|
return this;
|
|
1098
1219
|
}
|
package/lib/net.d.ts
CHANGED
|
@@ -98,6 +98,7 @@ export declare class Socket extends Duplex {
|
|
|
98
98
|
autoSelectFamilyAttemptedAddresses: string[];
|
|
99
99
|
private _autoSelectFamily;
|
|
100
100
|
private _timeout;
|
|
101
|
+
private _nativeWriteCallbacks;
|
|
101
102
|
get localFamily(): string;
|
|
102
103
|
get readyState(): string;
|
|
103
104
|
get pending(): boolean;
|
|
@@ -113,9 +114,7 @@ export declare class Socket extends Duplex {
|
|
|
113
114
|
connect(options: any, connectionListener?: () => void): this;
|
|
114
115
|
private _connect;
|
|
115
116
|
private _connectUnix;
|
|
116
|
-
end(
|
|
117
|
-
end(chunk: any, cb?: () => void): this;
|
|
118
|
-
end(chunk: any, encoding: string, cb?: () => void): this;
|
|
117
|
+
end(chunk?: any, encoding?: any, cb?: any): this;
|
|
119
118
|
_write(chunk: any, encoding: string, callback: (error?: Error | null) => void): void;
|
|
120
119
|
_read(size: number): void;
|
|
121
120
|
_final(callback: (error?: Error | null) => void): void;
|
package/lib/net.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"net.d.ts","sourceRoot":"","sources":["../src/net.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAI5C,OAAO,KAAK,EAAE,eAAe,EAAmB,SAAS,EAAE,MAAM,aAAa,CAAA;AAE9E,OAAO,EAAE,SAAS,EAAE,UAAU,EAA8B,MAAM,UAAU,CAAA;AAM5E,iBAAS,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAOnC;AAED,iBAAS,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEtC;AAED,iBAAS,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEtC;AA0BD,iBAAS,0B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