From ef1df685fca914d502d481be184bb26f94c39f9a Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Wed, 15 Dec 2021 02:16:37 +0100 Subject: [PATCH] Add experimental pause/resume HTTP body throttling --- src/HttpResponseWrapper.h | 23 +++++++++++++++++++++++ uWebSockets | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/HttpResponseWrapper.h b/src/HttpResponseWrapper.h index 0fd1abb..9f17e78 100644 --- a/src/HttpResponseWrapper.h +++ b/src/HttpResponseWrapper.h @@ -38,6 +38,26 @@ struct HttpResponseWrapper { args.Holder()->SetAlignedPointerInInternalField(0, nullptr); } + /* Takes nothing, returns this */ + template + static void res_pause(const FunctionCallbackInfo &args) { + auto *res = getHttpResponse(args); + if (res) { + res->pause(); + args.GetReturnValue().Set(args.Holder()); + } + } + + /* Takes nothing, returns this */ + template + static void res_resume(const FunctionCallbackInfo &args) { + auto *res = getHttpResponse(args); + if (res) { + res->resume(); + args.GetReturnValue().Set(args.Holder()); + } + } + /* Takes nothing, kills the connection */ template static void res_close(const FunctionCallbackInfo &args) { @@ -377,6 +397,9 @@ struct HttpResponseWrapper { resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getRemoteAddressAsText", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_getRemoteAddressAsText)); resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getProxiedRemoteAddress", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_getProxiedRemoteAddress)); resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getProxiedRemoteAddressAsText", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_getProxiedRemoteAddressAsText)); + resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "pause", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_pause)); + resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "resume", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_resume)); + /* Create our template */ Local resObjectLocal = resTemplateLocal->GetFunction(isolate->GetCurrentContext()).ToLocalChecked()->NewInstance(isolate->GetCurrentContext()).ToLocalChecked(); diff --git a/uWebSockets b/uWebSockets index e7d8355..6dc4a11 160000 --- a/uWebSockets +++ b/uWebSockets @@ -1 +1 @@ -Subproject commit e7d8355c37b06e424c7e9ffb1b1a20820764ac8e +Subproject commit 6dc4a11d1055202fc1a2bed21a0950c489b8b05f