aboutsummaryrefslogtreecommitdiff
path: root/packages/bun-uws/src
diff options
context:
space:
mode:
authorGravatar Dylan Conway <dylan.conway567@gmail.com> 2023-10-17 14:10:25 -0700
committerGravatar Dylan Conway <dylan.conway567@gmail.com> 2023-10-17 14:10:25 -0700
commit7458b969c5d9971e89d187b687e1924e78da427e (patch)
treeee3dbf95c728cf407bf49a27826b541e9264a8bd /packages/bun-uws/src
parentd4a2c29131ec154f5e4db897d4deedab2002cbc4 (diff)
parente91436e5248d947b50f90b4a7402690be8a41f39 (diff)
downloadbun-7458b969c5d9971e89d187b687e1924e78da427e.tar.gz
bun-7458b969c5d9971e89d187b687e1924e78da427e.tar.zst
bun-7458b969c5d9971e89d187b687e1924e78da427e.zip
Merge branch 'main' into postinstall_3
Diffstat (limited to 'packages/bun-uws/src')
-rw-r--r--packages/bun-uws/src/AsyncSocket.h11
-rw-r--r--packages/bun-uws/src/HttpResponse.h30
-rw-r--r--packages/bun-uws/src/Loop.h8
-rw-r--r--packages/bun-uws/src/LoopData.h1
4 files changed, 35 insertions, 15 deletions
diff --git a/packages/bun-uws/src/AsyncSocket.h b/packages/bun-uws/src/AsyncSocket.h
index 8e3301f24..1051271a2 100644
--- a/packages/bun-uws/src/AsyncSocket.h
+++ b/packages/bun-uws/src/AsyncSocket.h
@@ -121,18 +121,25 @@ public:
void corkUnchecked() {
/* What if another socket is corked? */
getLoopData()->corkedSocket = this;
+ getLoopData()->corkedSocketIsSSL = SSL;
}
/* Cork this socket. Only one socket may ever be corked per-loop at any given time */
void cork() {
/* Extra check for invalid corking of others */
if (getLoopData()->corkOffset && getLoopData()->corkedSocket != this) {
- std::cerr << "Error: Cork buffer must not be acquired without checking canCork!" << std::endl;
- std::terminate();
+ // We uncork the other socket early instead of terminating the program
+ // is unlikely to be cause any issues and is better than crashing
+ if(getLoopData()->corkedSocketIsSSL) {
+ ((AsyncSocket<true> *) getLoopData()->corkedSocket)->uncork();
+ } else {
+ ((AsyncSocket<false> *) getLoopData()->corkedSocket)->uncork();
+ }
}
/* What if another socket is corked? */
getLoopData()->corkedSocket = this;
+ getLoopData()->corkedSocketIsSSL = SSL;
}
/* Returns the corked socket or nullptr */
diff --git a/packages/bun-uws/src/HttpResponse.h b/packages/bun-uws/src/HttpResponse.h
index d73f98152..aa372e4e3 100644
--- a/packages/bun-uws/src/HttpResponse.h
+++ b/packages/bun-uws/src/HttpResponse.h
@@ -77,12 +77,12 @@ public:
writeHeader("Date", std::string_view(((LoopData *) us_loop_ext(us_socket_context_loop(SSL, (us_socket_context(SSL, (us_socket_t *) this)))))->date, 29));
/* You can disable this altogether */
-#ifndef UWS_HTTPRESPONSE_NO_WRITEMARK
- if (!Super::getLoopData()->noMark) {
- /* We only expose major version */
- writeHeader("uWebSockets", "20");
- }
-#endif
+// #ifndef UWS_HTTPRESPONSE_NO_WRITEMARK
+// if (!Super::getLoopData()->noMark) {
+// /* We only expose major version */
+// writeHeader("uWebSockets", "20");
+// }
+// #endif
}
/* Returns true on success, indicating that it might be feasible to write more data.
@@ -439,6 +439,24 @@ public:
return {internalEnd(data, totalSize, true, true, closeConnection), hasResponded()};
}
+ /* Write the end of chunked encoded stream */
+ bool sendTerminatingChunk(bool closeConnection = false) {
+ writeStatus(HTTP_200_OK);
+ HttpResponseData<SSL> *httpResponseData = getHttpResponseData();
+ if (!(httpResponseData->state & HttpResponseData<SSL>::HTTP_WRITE_CALLED)) {
+ /* Write mark on first call to write */
+ writeMark();
+
+ writeHeader("Transfer-Encoding", "chunked");
+ httpResponseData->state |= HttpResponseData<SSL>::HTTP_WRITE_CALLED;
+ }
+
+ /* Terminating 0 chunk */
+ Super::write("\r\n0\r\n\r\n", 7);
+
+ return internalEnd({nullptr, 0}, 0, false, false, closeConnection);
+ }
+
/* Write parts of the response in chunking fashion. Starts timeout if failed. */
bool write(std::string_view data) {
writeStatus(HTTP_200_OK);
diff --git a/packages/bun-uws/src/Loop.h b/packages/bun-uws/src/Loop.h
index 6c7bdfc9e..7311dd976 100644
--- a/packages/bun-uws/src/Loop.h
+++ b/packages/bun-uws/src/Loop.h
@@ -58,12 +58,6 @@ private:
for (auto &p : loopData->postHandlers) {
p.second((Loop *) loop);
}
-
- /* After every event loop iteration, we must not hold the cork buffer */
- if (loopData->corkedSocket) {
- std::cerr << "Error: Cork buffer must not be held across event loop iterations!" << std::endl;
- std::terminate();
- }
}
Loop() = delete;
@@ -132,7 +126,7 @@ public:
LoopData *loopData = (LoopData *) us_loop_ext((us_loop_t *) this);
/* Stop and free dateTimer first */
- us_timer_close(loopData->dateTimer);
+ us_timer_close(loopData->dateTimer, 1);
loopData->~LoopData();
/* uSockets will track whether this loop is owned by us or a borrowed alien loop */
diff --git a/packages/bun-uws/src/LoopData.h b/packages/bun-uws/src/LoopData.h
index 986bf0cbd..92bd9ffff 100644
--- a/packages/bun-uws/src/LoopData.h
+++ b/packages/bun-uws/src/LoopData.h
@@ -98,6 +98,7 @@ public:
char *corkBuffer = new char[CORK_BUFFER_SIZE];
unsigned int corkOffset = 0;
void *corkedSocket = nullptr;
+ bool corkedSocketIsSSL = false;
/* Per message deflate data */
ZlibContext *zlibContext = nullptr;