Skip to content

Commit 64b8e58

Browse files
Add maxRemainingBodyLength() wrapper and update uWebSockets submodule (#1237)
* Initial plan * Add maxRemainingBodyLength wrapper and update uWebSockets submodule Co-authored-by: uNetworkingAB <110806833+uNetworkingAB@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: uNetworkingAB <110806833+uNetworkingAB@users.noreply.github.com>
1 parent e1e8339 commit 64b8e58

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎docs/index.d.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ export interface HttpResponse {
170170
/** Returns the global byte write offset for this response. Use with onWritable. */
171171
getWriteOffset() : number;
172172

173+
/** Returns the max remaining body length of the currently read HTTP body. */
174+
maxRemainingBodyLength() : bigint;
175+
173176
/** Registers a handler for writable events. Continue failed write attempts in here.
174177
* You MUST return true for success, false for failure.
175178
* Writing nothing is always success, so by default you must return true.

‎src/HttpResponseWrapper.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,16 @@ struct HttpResponseWrapper {
312312
}
313313
}
314314

315+
/* Returns the max remaining body length */
316+
template <int SSL>
317+
static void res_maxRemainingBodyLength(const FunctionCallbackInfo<Value> &args) {
318+
Isolate *isolate = args.GetIsolate();
319+
auto *res = getHttpResponse<SSL>(args);
320+
if (res) {
321+
args.GetReturnValue().Set(BigInt::NewFromUnsigned(isolate, res->maxRemainingBodyLength()));
322+
}
323+
}
324+
315325
/* Takes function of bool(int), returns this */
316326
template <int SSL>
317327
static void res_onWritable(const FunctionCallbackInfo<Value> &args) {
@@ -574,6 +584,7 @@ struct HttpResponseWrapper {
574584
/* QUIC has a lot of functions unimplemented */
575585
if constexpr (SSL != 2) {
576586
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getWriteOffset", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_getWriteOffset<SSL>));
587+
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "maxRemainingBodyLength", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_maxRemainingBodyLength<SSL>));
577588
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getRemoteAddress", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_getRemoteAddress<SSL>));
578589
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "cork", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_cork<SSL>));
579590
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "collect", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_cork<SSL>));

‎uWebSockets‎

0 commit comments

Comments
 (0)