mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
chore: trim trailing space in uws (#20388)
This commit is contained in:
@@ -249,7 +249,7 @@ public:
|
||||
}
|
||||
|
||||
static TemplatedApp<SSL>* create(SocketContextOptions options = {}) {
|
||||
|
||||
|
||||
auto* httpContext = HttpContext<SSL>::create(Loop::get(), options);
|
||||
if (!httpContext) {
|
||||
return nullptr;
|
||||
@@ -646,4 +646,3 @@ typedef TemplatedApp<false> App;
|
||||
typedef TemplatedApp<true> SSLApp;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -224,7 +224,7 @@ public:
|
||||
|
||||
/**
|
||||
* Flushes the socket buffer by writing as much data as possible to the underlying socket.
|
||||
*
|
||||
*
|
||||
* @return The total number of bytes successfully written to the socket
|
||||
*/
|
||||
size_t flush() {
|
||||
@@ -237,24 +237,24 @@ public:
|
||||
/* Get the associated asynchronous socket data structure */
|
||||
AsyncSocketData<SSL> *asyncSocketData = getAsyncSocketData();
|
||||
size_t total_written = 0;
|
||||
|
||||
|
||||
/* Continue flushing as long as we have data in the buffer */
|
||||
while (asyncSocketData->buffer.length()) {
|
||||
/* Get current buffer size */
|
||||
size_t buffer_len = asyncSocketData->buffer.length();
|
||||
|
||||
|
||||
/* Limit write size to INT_MAX as the underlying socket API uses int for length */
|
||||
int max_flush_len = std::min(buffer_len, (size_t)INT_MAX);
|
||||
|
||||
/* Attempt to write data to the socket */
|
||||
int written = us_socket_write(SSL, (us_socket_t *) this, asyncSocketData->buffer.data(), max_flush_len, 0);
|
||||
total_written += written;
|
||||
|
||||
|
||||
/* Check if we couldn't write the entire buffer */
|
||||
if ((unsigned int) written < buffer_len) {
|
||||
/* Remove the successfully written data from the buffer */
|
||||
asyncSocketData->buffer.erase((unsigned int) written);
|
||||
|
||||
|
||||
/* If we wrote less than we attempted, the socket buffer is likely full
|
||||
* likely is used as an optimization hint to the compiler
|
||||
* since written < buffer_len is very likely to be true
|
||||
@@ -317,7 +317,7 @@ public:
|
||||
asyncSocketData->buffer.clear();
|
||||
}
|
||||
|
||||
if (length) {
|
||||
if (length) {
|
||||
if (loopData->isCorkedWith(this)) {
|
||||
/* We are corked */
|
||||
if (LoopData::CORK_BUFFER_SIZE - loopData->getCorkOffset() >= (unsigned int) length) {
|
||||
|
||||
@@ -52,7 +52,7 @@ public:
|
||||
if (key.length() < 2) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
ScrambleArea s = getFeatures(key);
|
||||
s.val = perfectHash(s.val);
|
||||
return filter[s.p[0]] &&
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace uWS {
|
||||
data.remove_prefix(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
auto len = data.length();
|
||||
if(len) {
|
||||
// consume extension
|
||||
@@ -93,20 +93,20 @@ namespace uWS {
|
||||
/* RFC 9110: Token format (TLDR; anything bellow 32 is not allowed)
|
||||
* TODO: add support for quoted-strings values (RFC 9110: 3.2.6. Quoted-String)
|
||||
* Example of chunked encoding with extensions:
|
||||
*
|
||||
*
|
||||
* 4;key=value\r\n
|
||||
* Wiki\r\n
|
||||
* 5;foo=bar;baz=quux\r\n
|
||||
* pedia\r\n
|
||||
* 0\r\n
|
||||
* \r\n
|
||||
*
|
||||
*
|
||||
* The chunk size is in hex (4, 5, 0), followed by optional
|
||||
* semicolon-separated extensions. Extensions consist of a key
|
||||
* (token) and optional value. The value may be a token or a
|
||||
* quoted string. The chunk data follows the CRLF after the
|
||||
* extensions and must be exactly the size specified.
|
||||
*
|
||||
*
|
||||
* RFC 7230 Section 4.1.1 defines chunk extensions as:
|
||||
* chunk-ext = *( ";" chunk-ext-name [ "=" chunk-ext-val ] )
|
||||
* chunk-ext-name = token
|
||||
@@ -116,7 +116,7 @@ namespace uWS {
|
||||
state = STATE_IS_ERROR;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
data.remove_prefix(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,5 +17,5 @@ namespace uWS {
|
||||
//printf("Constructing http3contextdata: %p\n", this);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
@@ -77,7 +77,7 @@ namespace uWS {
|
||||
|
||||
/* If not already written */
|
||||
writeStatus("200 OK");
|
||||
|
||||
|
||||
// has body is determined by the ending so this is perfect here
|
||||
us_quic_socket_context_send_headers(nullptr, (us_quic_stream_t *) this, responseData->headerOffset, data.length() > 0);
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace uWS {
|
||||
|
||||
/* Status is always first header just like for h1 */
|
||||
unsigned int headerOffset = 0;
|
||||
|
||||
|
||||
/* Write offset */
|
||||
uint64_t offset = 0;
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ private:
|
||||
MACRO("UNLINK") \
|
||||
MACRO("UNLOCK") \
|
||||
MACRO("UNSUBSCRIBE") \
|
||||
|
||||
|
||||
|
||||
#ifndef _WIN32
|
||||
static constexpr std::array<const std::string, 35> HTTP_METHODS = {
|
||||
@@ -108,12 +108,12 @@ private:
|
||||
FOR_EACH_HTTP_METHOD(MACRO)
|
||||
#undef MACRO
|
||||
};
|
||||
|
||||
|
||||
static std::span<const std::string> getAllHttpMethods() {
|
||||
static std::once_flag flag;
|
||||
static std::array<std::string, 35> methods;
|
||||
std::call_once(flag, []() {
|
||||
methods = {
|
||||
methods = {
|
||||
#define MACRO(name) std::string {name},
|
||||
FOR_EACH_HTTP_METHOD(MACRO)
|
||||
#undef MACRO
|
||||
@@ -201,7 +201,7 @@ private:
|
||||
/* Call filter */
|
||||
HttpContextData<SSL> *httpContextData = getSocketContextDataS(s);
|
||||
|
||||
|
||||
|
||||
for (auto &f : httpContextData->filterHandlers) {
|
||||
f((HttpResponse<SSL> *) s, -1);
|
||||
}
|
||||
@@ -276,7 +276,7 @@ private:
|
||||
|
||||
/* Mark pending request and emit it */
|
||||
httpResponseData->state = HttpResponseData<SSL>::HTTP_RESPONSE_PENDING;
|
||||
|
||||
|
||||
|
||||
/* Mark this response as connectionClose if ancient or connection: close */
|
||||
if (httpRequest->isAncient() || httpRequest->getHeader("connection").length() == 5) {
|
||||
@@ -336,7 +336,7 @@ private:
|
||||
}, [httpResponseData](void *user, std::string_view data, bool fin) -> void * {
|
||||
/* We always get an empty chunk even if there is no data */
|
||||
if (httpResponseData->inStream) {
|
||||
|
||||
|
||||
/* Todo: can this handle timeout for non-post as well? */
|
||||
if (fin) {
|
||||
/* If we just got the last chunk (or empty chunk), disable timeout */
|
||||
@@ -374,7 +374,7 @@ private:
|
||||
});
|
||||
|
||||
auto httpErrorStatusCode = result.httpErrorStatusCode();
|
||||
|
||||
|
||||
/* Mark that we are no longer parsing Http */
|
||||
httpContextData->flags.isParsingHttp = false;
|
||||
/* If we got fullptr that means the parser wants us to close the socket from error (same as calling the errorHandler) */
|
||||
@@ -388,7 +388,7 @@ private:
|
||||
/* Close any socket on HTTP errors */
|
||||
us_socket_close(SSL, s, 0, nullptr);
|
||||
}
|
||||
|
||||
|
||||
auto returnedData = result.returnedData;
|
||||
/* We need to uncork in all cases, except for nullptr (closed socket, or upgraded socket) */
|
||||
if (returnedData != nullptr) {
|
||||
@@ -471,12 +471,12 @@ private:
|
||||
* and will fall through to the next section of code
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/* Ask the developer to write data and return success (true) or failure (false), OR skip sending anything and return success (true). */
|
||||
if (httpResponseData->onWritable) {
|
||||
/* We are now writable, so hang timeout again, the user does not have to do anything so we should hang until end or tryEnd rearms timeout */
|
||||
us_socket_timeout(SSL, s, 0);
|
||||
|
||||
|
||||
/* We expect the developer to return whether or not write was successful (true).
|
||||
* If write was never called, the developer should still return true so that we may drain. */
|
||||
bool success = httpResponseData->callOnWritable(reinterpret_cast<HttpResponse<SSL> *>(asyncSocket), httpResponseData->offset);
|
||||
@@ -497,7 +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 */
|
||||
@@ -588,7 +588,7 @@ public:
|
||||
methods = getAllHttpMethods();
|
||||
} else {
|
||||
methods_buffer[0] = std::string(method);
|
||||
methods = {methods_buffer.data(), 1};
|
||||
methods = {methods_buffer.data(), 1};
|
||||
}
|
||||
|
||||
uint32_t priority = method == "*" ? httpContextData->currentRouter->LOW_PRIORITY : (upgrade ? httpContextData->currentRouter->HIGH_PRIORITY : httpContextData->currentRouter->MEDIUM_PRIORITY);
|
||||
@@ -616,7 +616,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
httpContextData->currentRouter->add(methods, pattern, [handler = std::move(handler), parameterOffsets = std::move(parameterOffsets), httpContextData](auto *r) mutable {
|
||||
auto user = r->getUserData();
|
||||
@@ -667,5 +667,3 @@ public:
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -39,4 +39,3 @@ static const std::string_view httpErrorResponses[] = {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ namespace uWS
|
||||
}
|
||||
|
||||
|
||||
/* Returns true if there was an error */
|
||||
/* Returns true if there was an error */
|
||||
bool isError() {
|
||||
return parserError != HTTP_PARSER_ERROR_NONE;
|
||||
}
|
||||
@@ -403,7 +403,7 @@ namespace uWS
|
||||
|
||||
static bool isValidMethod(std::string_view str, bool useStrictMethodValidation) {
|
||||
if (str.empty()) return false;
|
||||
|
||||
|
||||
if (useStrictMethodValidation) {
|
||||
return Bun__HTTPMethod__from(str.data(), str.length()) != -1;
|
||||
}
|
||||
@@ -613,13 +613,13 @@ namespace uWS
|
||||
return HttpParserResult::shortRead();
|
||||
}
|
||||
postPaddedBuffer = requestLineResult.position;
|
||||
|
||||
|
||||
if(requestLineResult.isAncientHTTP) {
|
||||
isAncientHTTP = true;
|
||||
}
|
||||
/* No request headers found */
|
||||
const char * headerStart = (headers[0].key.length() > 0) ? headers[0].key.data() : end;
|
||||
|
||||
|
||||
/* Check if we can see if headers follow or not */
|
||||
if (postPaddedBuffer + 2 > end) {
|
||||
/* Not enough data to check for \r\n */
|
||||
@@ -711,7 +711,7 @@ namespace uWS
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
|
||||
if(postPaddedBuffer[0] == '\r') {
|
||||
// invalid char after \r
|
||||
return HttpParserResult::error(HTTP_ERROR_400_BAD_REQUEST, HTTP_PARSER_ERROR_INVALID_REQUEST);
|
||||
@@ -757,7 +757,7 @@ namespace uWS
|
||||
|
||||
/* Add all headers to bloom filter */
|
||||
req->bf.reset();
|
||||
|
||||
|
||||
for (HttpRequest::Header *h = req->headers; (++h)->key.length(); ) {
|
||||
req->bf.add(h->key);
|
||||
}
|
||||
@@ -864,7 +864,7 @@ namespace uWS
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return HttpParserResult::success(consumedTotal, user);
|
||||
}
|
||||
|
||||
@@ -1000,4 +1000,3 @@ public:
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -106,7 +106,7 @@ public:
|
||||
if (closeConnection) {
|
||||
/* We can only write the header once */
|
||||
if (!(httpResponseData->state & (HttpResponseData<SSL>::HTTP_END_CALLED))) {
|
||||
|
||||
|
||||
/* HTTP 1.1 must send this back unless the client already sent it to us.
|
||||
* It is a connection close when either of the two parties say so but the
|
||||
* one party must tell the other one so.
|
||||
@@ -125,10 +125,10 @@ public:
|
||||
|
||||
/* We do not have tryWrite-like functionalities, so ignore optional in this path */
|
||||
|
||||
|
||||
|
||||
/* Write the chunked data if there is any (this will not send zero chunks) */
|
||||
this->write(data, nullptr);
|
||||
|
||||
|
||||
|
||||
/* Terminating 0 chunk */
|
||||
Super::write("0\r\n\r\n", 5);
|
||||
@@ -470,7 +470,7 @@ public:
|
||||
writeStatus(HTTP_200_OK);
|
||||
|
||||
HttpResponseData<SSL> *httpResponseData = getHttpResponseData();
|
||||
|
||||
|
||||
if (!(httpResponseData->state & HttpResponseData<SSL>::HTTP_WROTE_CONTENT_LENGTH_HEADER) && !httpResponseData->fromAncientRequest) {
|
||||
if (!(httpResponseData->state & HttpResponseData<SSL>::HTTP_WRITE_CALLED)) {
|
||||
/* Write mark on first call to write */
|
||||
@@ -532,7 +532,7 @@ public:
|
||||
}
|
||||
return !has_failed;
|
||||
}
|
||||
|
||||
|
||||
|
||||
HttpResponseData<SSL> *httpResponseData = getHttpResponseData();
|
||||
|
||||
@@ -545,7 +545,7 @@ public:
|
||||
Super::write("\r\n", 2);
|
||||
httpResponseData->state |= HttpResponseData<SSL>::HTTP_WRITE_CALLED;
|
||||
}
|
||||
|
||||
|
||||
writeUnsignedHex((unsigned int) data.length());
|
||||
Super::write("\r\n", 2);
|
||||
} else if (!(httpResponseData->state & HttpResponseData<SSL>::HTTP_WRITE_CALLED)) {
|
||||
@@ -578,7 +578,7 @@ public:
|
||||
// Write End of Chunked Encoding after data has been written
|
||||
Super::write("\r\n", 2);
|
||||
}
|
||||
|
||||
|
||||
/* Reset timeout on each sended chunk */
|
||||
this->resetTimeout();
|
||||
|
||||
|
||||
@@ -109,5 +109,3 @@ struct HttpResponseData : AsyncSocketData<SSL>, HttpParser {
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ private:
|
||||
LoopData *loopData = (LoopData *) us_loop_ext((struct us_loop_t *) loop);
|
||||
loopData->dateTimer = us_create_timer((struct us_loop_t *) loop, 1, sizeof(LoopData *));
|
||||
loopData->updateDate();
|
||||
|
||||
|
||||
memcpy(us_timer_ext(loopData->dateTimer), &loopData, sizeof(LoopData *));
|
||||
us_timer_set(loopData->dateTimer, [](struct us_timer_t *t) {
|
||||
LoopData *loopData;
|
||||
@@ -103,7 +103,7 @@ private:
|
||||
~LoopCleaner() {
|
||||
// There's no need to call this destructor if Bun is in the process of exiting.
|
||||
// This is both a performance thing, and also to prevent freeing some things which are not meant to be freed
|
||||
// such as uv_tty_t
|
||||
// such as uv_tty_t
|
||||
if(loop && cleanMe && !bun_is_exiting()) {
|
||||
cleanMe = false;
|
||||
loop->free();
|
||||
|
||||
@@ -97,11 +97,11 @@ public:
|
||||
this->corkedSocket = nullptr;
|
||||
this->corkOffset = 0;
|
||||
}
|
||||
|
||||
|
||||
unsigned int getCorkOffset() {
|
||||
return this->corkOffset;
|
||||
}
|
||||
|
||||
|
||||
void setCorkOffset(unsigned int offset) {
|
||||
this->corkOffset = offset;
|
||||
}
|
||||
@@ -109,7 +109,7 @@ public:
|
||||
void incrementCorkedOffset(unsigned int offset) {
|
||||
this->corkOffset += offset;
|
||||
}
|
||||
|
||||
|
||||
char* getCorkBuffer() {
|
||||
return this->corkBuffer;
|
||||
}
|
||||
|
||||
@@ -260,7 +260,7 @@ public:
|
||||
/* This one always resets needsDrainage before it calls any cb's.
|
||||
* Otherwise we would stackoverflow when sending after publish but before drain. */
|
||||
drainImpl(s);
|
||||
|
||||
|
||||
/* If we drained last subscriber, also clear outgoingMessages */
|
||||
if (!drainableSubscribers) {
|
||||
outgoingMessages.clear();
|
||||
@@ -363,5 +363,3 @@ public:
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user