Add experimental pause/resume HTTP body throttling

This commit is contained in:
Alex Hultman 2021-12-15 02:16:37 +01:00
parent be3535b6f1
commit ef1df685fc
2 changed files with 24 additions and 1 deletions

View File

@ -38,6 +38,26 @@ struct HttpResponseWrapper {
args.Holder()->SetAlignedPointerInInternalField(0, nullptr);
}
/* Takes nothing, returns this */
template <bool SSL>
static void res_pause(const FunctionCallbackInfo<Value> &args) {
auto *res = getHttpResponse<SSL>(args);
if (res) {
res->pause();
args.GetReturnValue().Set(args.Holder());
}
}
/* Takes nothing, returns this */
template <bool SSL>
static void res_resume(const FunctionCallbackInfo<Value> &args) {
auto *res = getHttpResponse<SSL>(args);
if (res) {
res->resume();
args.GetReturnValue().Set(args.Holder());
}
}
/* Takes nothing, kills the connection */
template <bool SSL>
static void res_close(const FunctionCallbackInfo<Value> &args) {
@ -377,6 +397,9 @@ struct HttpResponseWrapper {
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getRemoteAddressAsText", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_getRemoteAddressAsText<SSL>));
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getProxiedRemoteAddress", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_getProxiedRemoteAddress<SSL>));
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getProxiedRemoteAddressAsText", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_getProxiedRemoteAddressAsText<SSL>));
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "pause", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_pause<SSL>));
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "resume", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_resume<SSL>));
/* Create our template */
Local<Object> resObjectLocal = resTemplateLocal->GetFunction(isolate->GetCurrentContext()).ToLocalChecked()->NewInstance(isolate->GetCurrentContext()).ToLocalChecked();

@ -1 +1 @@
Subproject commit e7d8355c37b06e424c7e9ffb1b1a20820764ac8e
Subproject commit 6dc4a11d1055202fc1a2bed21a0950c489b8b05f