mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
Add FileRoute for serving files (#20198)
Co-authored-by: Jarred-Sumner <709451+Jarred-Sumner@users.noreply.github.com> Co-authored-by: Dylan Conway <dylan.conway567@gmail.com> Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com> Co-authored-by: Ciro Spaciari <ciro.spaciari@gmail.com>
This commit is contained in:
@@ -260,7 +260,7 @@ public:
|
||||
* since written < buffer_len is very likely to be true
|
||||
*/
|
||||
if(written < max_flush_len) {
|
||||
[[likely]]
|
||||
[[likely]]
|
||||
/* Cannot write more at this time, return what we've written so far */
|
||||
return total_written;
|
||||
}
|
||||
|
||||
@@ -456,10 +456,9 @@ private:
|
||||
size_t bufferedAmount = asyncSocket->getBufferedAmount();
|
||||
if (bufferedAmount > 0) {
|
||||
/* Try to flush pending data from the socket's buffer to the network */
|
||||
bufferedAmount -= asyncSocket->flush();
|
||||
|
||||
asyncSocket->flush();
|
||||
/* Check if there's still data waiting to be sent after flush attempt */
|
||||
if (bufferedAmount > 0) {
|
||||
if (asyncSocket->getBufferedAmount() > 0) {
|
||||
/* Socket buffer is not completely empty yet
|
||||
* - Reset the timeout to prevent premature connection closure
|
||||
* - This allows time for another writable event or new request
|
||||
@@ -498,6 +497,7 @@ private:
|
||||
if (httpResponseData->state & HttpResponseData<SSL>::HTTP_CONNECTION_CLOSE) {
|
||||
if ((httpResponseData->state & HttpResponseData<SSL>::HTTP_RESPONSE_PENDING) == 0) {
|
||||
if (asyncSocket->getBufferedAmount() == 0) {
|
||||
|
||||
asyncSocket->shutdown();
|
||||
/* We need to force close after sending FIN since we want to hinder
|
||||
* clients from keeping to send their huge data */
|
||||
|
||||
@@ -112,7 +112,7 @@ public:
|
||||
* one party must tell the other one so.
|
||||
*
|
||||
* This check also serves to limit writing the header only once. */
|
||||
if ((httpResponseData->state & HttpResponseData<SSL>::HTTP_CONNECTION_CLOSE) == 0) {
|
||||
if ((httpResponseData->state & HttpResponseData<SSL>::HTTP_CONNECTION_CLOSE) == 0 && !(httpResponseData->state & (HttpResponseData<SSL>::HTTP_WRITE_CALLED))) {
|
||||
writeHeader("Connection", "close");
|
||||
}
|
||||
|
||||
@@ -132,7 +132,6 @@ public:
|
||||
|
||||
/* Terminating 0 chunk */
|
||||
Super::write("0\r\n\r\n", 5);
|
||||
|
||||
httpResponseData->markDone();
|
||||
|
||||
/* We need to check if we should close this socket here now */
|
||||
@@ -586,7 +585,6 @@ public:
|
||||
if (writtenPtr) {
|
||||
*writtenPtr = total_written;
|
||||
}
|
||||
|
||||
/* If we did not fail the write, accept more */
|
||||
return !has_failed;
|
||||
}
|
||||
|
||||
@@ -118,7 +118,6 @@ public:
|
||||
time_t now = time(0);
|
||||
struct tm tstruct = {};
|
||||
#ifdef _WIN32
|
||||
/* Micro, fucking soft never follows spec. */
|
||||
gmtime_s(&tstruct, &now);
|
||||
#else
|
||||
gmtime_r(&now, &tstruct);
|
||||
|
||||
Reference in New Issue
Block a user