mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-06 00:13:33 +00:00
1. Updated http-diget to not chunk requests, working around AMT TLS bug
2. Fixed bug in http persistent connections, where 2nd request would close the socket when client request is 'end'ed. 3. Added debug logging/instrumentation to readable and writable stream
This commit is contained in:
@@ -67,6 +67,7 @@ void ILibDuktape_RemoveObjFromTable(duk_context *ctx, duk_idx_t tableIdx, char *
|
||||
#define ILibDuktape_IMSG2SR "\xFF_IMSG2ServerResponse"
|
||||
#define ILibDuktape_NS2HttpServer "\xFF_Http_NetServer2HttpServer"
|
||||
#define ILibDuktape_Options2ClientRequest "\xFF_Options2ClientRequest"
|
||||
#define ILibDuktape_RawOptionsBuffer "\xFF_RawOptionsBuffer"
|
||||
#define ILibDuktape_Socket2AgentStash "\xFF_Socket2AgentStash"
|
||||
#define ILibDuktape_Socket2Agent "\xFF_Socket2Agent"
|
||||
#define ILibDuktape_Socket2AgentKey "\xFF_Socket2AgentKey"
|
||||
@@ -648,9 +649,6 @@ duk_ret_t ILibDuktape_HttpStream_http_endResponseSink(duk_context *ctx)
|
||||
duk_insert(ctx, -4); // [socket][imsg][httpstream][CR]
|
||||
|
||||
ILibDuktape_DeleteReadOnlyProperty(ctx, -1, "socket");
|
||||
ILibDuktape_DeleteReadOnlyProperty(ctx, -2, ILibDuktape_HTTPStream2Socket);
|
||||
ILibDuktape_DeleteReadOnlyProperty(ctx, -4, ILibDuktape_Socket2HttpStream);
|
||||
duk_del_prop_string(ctx, -2, ILibDuktape_HTTP2PipedReadable);
|
||||
|
||||
duk_prepare_method_call(ctx, -1, "removeAllListeners"); // [socket][imsg][httpstream][CR][remove][this]
|
||||
duk_pcall_method(ctx, 0); duk_pop(ctx); // [socket][imsg][httpstream][CR]
|
||||
@@ -658,6 +656,10 @@ duk_ret_t ILibDuktape_HttpStream_http_endResponseSink(duk_context *ctx)
|
||||
if (Duktape_GetBooleanProperty(ctx, -2, "connectionCloseSpecified", 0) != 0)
|
||||
{
|
||||
// We cant persist this connection, so close the socket.
|
||||
ILibDuktape_DeleteReadOnlyProperty(ctx, -2, ILibDuktape_HTTPStream2Socket);
|
||||
ILibDuktape_DeleteReadOnlyProperty(ctx, -4, ILibDuktape_Socket2HttpStream);
|
||||
duk_del_prop_string(ctx, -2, ILibDuktape_HTTP2PipedReadable);
|
||||
|
||||
// Agent is already listening for the 'close' event, so it'll cleanup automatically
|
||||
duk_prepare_method_call(ctx, -2, "unpipe"); // [socket][imsg][httpstream][CR][unpipe][this]
|
||||
duk_pcall_method(ctx, 0); duk_pop(ctx); // [socket][imsg][httpstream][CR]
|
||||
@@ -877,7 +879,10 @@ duk_ret_t ILibDuktape_HttpStream_http_OnSocketReady(duk_context *ctx)
|
||||
duk_get_prop_string(ctx, -1, "pipe"); // [socket][clientRequest][HTTPStream][destination][Options][clientRequest][pipe]
|
||||
duk_swap_top(ctx, -2); // [socket][clientRequest][HTTPStream][destination][Options][pipe][this]
|
||||
duk_dup(ctx, -4); // [socket][clientRequest][HTTPStream][destination][Options][pipe][this][destination]
|
||||
duk_call_method(ctx, 1);
|
||||
duk_push_object(ctx); // [socket][clientRequest][HTTPStream][destination][Options][pipe][this][destination][options]
|
||||
duk_push_false(ctx); duk_put_prop_string(ctx, -2, "end"); // [socket][clientRequest][HTTPStream][destination][Options][pipe][this][destination][options]
|
||||
|
||||
duk_call_method(ctx, 2);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -972,6 +972,38 @@ duk_ret_t ILibDuktape_ReadableStream__pipedStreams(duk_context *ctx)
|
||||
duk_get_prop_string(ctx, -1, ILibDuktape_readableStream_PipeArray); // [readable][array]
|
||||
return(1);
|
||||
}
|
||||
duk_ret_t ILibDuktape_ReadableStream_getBufferedWrites(duk_context *ctx)
|
||||
{
|
||||
ILibDuktape_readableStream *rs;
|
||||
duk_push_this(ctx); // [stream]
|
||||
rs = (ILibDuktape_readableStream*)Duktape_GetBufferProperty(ctx, -1, ILibDuktape_readableStream_RSPTRS);
|
||||
if (rs == NULL) { return(ILibDuktape_Error(ctx, "Internal Error, RS NULL")); }
|
||||
ILibDuktape_readableStream_bufferedData *buffered = rs->paused_data;
|
||||
if (rs->paused_data == NULL) { return(ILibDuktape_Error(ctx, "No Buffered Data")); }
|
||||
|
||||
duk_eval_string(ctx, "Buffer.concat"); // [concat]
|
||||
duk_push_array(ctx); // [concat][list]
|
||||
|
||||
while (buffered!=NULL)
|
||||
{
|
||||
duk_push_external_buffer(ctx); // [concat][list][extbuff]
|
||||
duk_config_buffer(ctx, -1, buffered->buffer, buffered->bufferLen);
|
||||
duk_push_buffer_object(ctx, -1, 0, buffered->bufferLen, DUK_BUFOBJ_NODEJS_BUFFER);
|
||||
duk_remove(ctx, -2); // [concat][list][buffer]
|
||||
duk_array_push(ctx, -2); // [concat][list]
|
||||
buffered = buffered->Next;
|
||||
}
|
||||
|
||||
duk_call(ctx, 1); // [buffer]
|
||||
|
||||
while ((buffered = rs->paused_data))
|
||||
{
|
||||
rs->paused_data = buffered->Next;
|
||||
free(buffered);
|
||||
}
|
||||
|
||||
return(1);
|
||||
}
|
||||
ILibDuktape_readableStream* ILibDuktape_ReadableStream_InitEx(duk_context *ctx, ILibDuktape_readableStream_PauseResumeHandler OnPause, ILibDuktape_readableStream_PauseResumeHandler OnResume, ILibDuktape_readableStream_UnShiftHandler OnUnshift, void *user)
|
||||
{
|
||||
ILibDuktape_readableStream *retVal;
|
||||
@@ -1007,5 +1039,6 @@ ILibDuktape_readableStream* ILibDuktape_ReadableStream_InitEx(duk_context *ctx,
|
||||
ILibDuktape_CreateInstanceMethod(ctx, "isPaused", ILibDuktape_readableStream_isPaused, 0);
|
||||
ILibDuktape_CreateInstanceMethod(ctx, "unshift", ILibDuktape_ReadableStream_unshift, 1);
|
||||
ILibDuktape_CreateEventWithGetter(ctx, "_pipedStreams", ILibDuktape_ReadableStream__pipedStreams);
|
||||
ILibDuktape_CreateInstanceMethod(ctx, "_getBufferedWrites", ILibDuktape_ReadableStream_getBufferedWrites, 0);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@@ -312,7 +312,7 @@ duk_ret_t ILibDuktape_WritableStream_PipeSink(duk_context *ctx)
|
||||
|
||||
duk_dup(ctx, 0);
|
||||
duk_push_this(ctx);
|
||||
if (g_displayStreamPipeMessages) { printf("PIPE: [%s] => [%s:%d]\n", Duktape_GetStringPropertyValue(ctx, -2, ILibDuktape_OBJID, "unknown"), Duktape_GetStringPropertyValue(ctx, -1, ILibDuktape_OBJID, "unknown"), ILibDuktape_GetReferenceCount(ctx, -1)); }
|
||||
if (g_displayStreamPipeMessages) { printf("PIPE: [%s/%p] => [%s:%d]\n", Duktape_GetStringPropertyValue(ctx, -2, ILibDuktape_OBJID, "unknown"), (void*)ws, Duktape_GetStringPropertyValue(ctx, -1, ILibDuktape_OBJID, "unknown"), ILibDuktape_GetReferenceCount(ctx, -1)); }
|
||||
return(0);
|
||||
}
|
||||
duk_ret_t ILibDuktape_WritableStream_Ended(duk_context *ctx)
|
||||
|
||||
@@ -158,7 +158,6 @@ function http_digest_instance(options)
|
||||
{
|
||||
this._buffered = Buffer.concat([this._buffered, chunk], this._buffered.length + chunk.length);
|
||||
}
|
||||
|
||||
if (this._request)
|
||||
{
|
||||
if (this.writeCalledByEnd())
|
||||
@@ -170,6 +169,7 @@ function http_digest_instance(options)
|
||||
this._request.write(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
if (flush != null) { flush(); }
|
||||
return (true);
|
||||
},
|
||||
@@ -177,7 +177,14 @@ function http_digest_instance(options)
|
||||
{
|
||||
if (this._ended) { throw ('Stream already ended'); }
|
||||
this._ended = true;
|
||||
if (this._request && !this.writeCalledByEnd()) { this._request.end(); }
|
||||
if (!(this.options && this.options.delayWrite))
|
||||
{
|
||||
if (this._request && !this.writeCalledByEnd()) { this._request.end(); }
|
||||
}
|
||||
else
|
||||
{
|
||||
this._request.end();
|
||||
}
|
||||
if (flush != null) { flush(); }
|
||||
}
|
||||
});
|
||||
@@ -235,15 +242,19 @@ function http_digest_instance(options)
|
||||
|
||||
ret._request.once('response', function (imsg)
|
||||
{
|
||||
console.info1('response status code => ' + imsg.statusCode);
|
||||
if (imsg.statusCode == 401)
|
||||
{
|
||||
var callend = this.digRequest._request._callend;
|
||||
var auth = generateAuthHeaders(imsg, this.digRequest.options, this.digRequest._digest);
|
||||
|
||||
console.info1(JSON.stringify(auth, null, 1));
|
||||
console.info1(JSON.stringify(this.digRequest.options, null, 1));
|
||||
this.digRequest._request = this.digRequest._digest.http.request(this.digRequest.options);
|
||||
this.digRequest._request.digRequest = this.digRequest;
|
||||
this.digRequest._request.once('response', function (imsg)
|
||||
{
|
||||
console.info1('inner response status code => ' + imsg.statusCode);
|
||||
|
||||
switch(imsg.statusCode)
|
||||
{
|
||||
case 401:
|
||||
@@ -259,14 +270,23 @@ function http_digest_instance(options)
|
||||
checkEventForwarding(this.digRequest, 'continue');
|
||||
checkEventForwarding(this.digRequest, 'timeout');
|
||||
checkEventForwarding(this.digRequest, 'drain');
|
||||
|
||||
|
||||
if (callend)
|
||||
{
|
||||
this.digRequest._request.end();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.digRequest._buffered) { this.digRequest._request.write(this.digRequest._buffered); }
|
||||
if (this.digRequest._ended) { this.digRequest._request.end(); }
|
||||
if (this.digRequest._buffered && this.digRequest._ended)
|
||||
{
|
||||
this.digRequest._request.end(this.digRequest._buffered);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.digRequest._buffered) { this.digRequest._request.write(this.digRequest._buffered); }
|
||||
if (this.digRequest._ended) { this.digRequest._request.end(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user