Skip to content

Commit faf1152

Browse files
Copilot/clean beginwrite (#1293)
* Bump uWS and wrap beginWrite in HttpResponse * Address code review feedback by enhancing comments in res_beginWrite --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent fbdac03 commit faf1152

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎docs/index.d.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ export interface HttpResponse {
157157
writeHeader(key: RecognizedString, value: RecognizedString) : HttpResponse;
158158
/** Enters or continues chunked encoding mode. Writes part of the response. End with zero length write. Returns true if no backpressure was added. */
159159
write(chunk: RecognizedString) : boolean;
160+
/** Begins chunked encoding mode and flushes headers immediately. */
161+
beginWrite() : HttpResponse;
160162
/** Ends this response by copying the contents of body. */
161163
end(body?: RecognizedString, closeConnection?: boolean) : HttpResponse;
162164
/** Ends this response without a body. */

‎src/HttpResponseWrapper.h‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,19 @@ struct HttpResponseWrapper {
479479
}
480480
}
481481

482+
/* Begins chunked encoding mode and flushes headers immediately. Takes nothing, returns this */
483+
template <int SSL>
484+
static void res_beginWrite(const FunctionCallbackInfo<Value> &args) {
485+
auto *res = getHttpResponse<SSL>(args);
486+
if (res) {
487+
/* We assume the user has called cork() or we are inside an implicit corked handler context */
488+
assumeCorked();
489+
res->beginWrite();
490+
491+
args.GetReturnValue().Set(args.This());
492+
}
493+
}
494+
482495
/* Takes key, value. Returns this */
483496
template <int PROTOCOL>
484497
static void res_writeHeader(const FunctionCallbackInfo<Value> &args) {
@@ -600,6 +613,7 @@ struct HttpResponseWrapper {
600613
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "onDataV2", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_onDataV2<SSL>));
601614
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "collectBody", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_collectBody<SSL>));
602615
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getWriteOffset", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_getWriteOffset<SSL>));
616+
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "beginWrite", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_beginWrite<SSL>));
603617
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getRemoteAddress", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_getRemoteAddress<SSL>));
604618
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "cork", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_cork<SSL>));
605619
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "collect", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, res_cork<SSL>));

‎uWebSockets‎

0 commit comments

Comments
 (0)