Pull some upstream changes from uWS (#16275)

This commit is contained in:
Jarred Sumner
2025-01-10 03:05:24 -08:00
committed by GitHub
parent 5e584e9a54
commit cfa4998d24
2 changed files with 18 additions and 8 deletions

View File

@@ -432,8 +432,9 @@ public:
/* Try and end the response. Returns [true, true] on success.
* Starts a timeout in some cases. Returns [ok, hasResponded] */
std::pair<bool, bool> tryEnd(std::string_view data, uint64_t totalSize = 0, bool closeConnection = false) {
return {internalEnd(data, totalSize, true, true, closeConnection), hasResponded()};
std::pair<bool, bool> tryEnd(std::string_view data, uintmax_t totalSize = 0, bool closeConnection = false) {
bool ok = internalEnd(data, totalSize, true, true, closeConnection);
return {ok, hasResponded()};
}
/* Write the end of chunked encoded stream */

View File

@@ -256,7 +256,7 @@ private:
std::string segment = std::string(getUrlSegment(i).first);
Node *next = nullptr;
for (std::unique_ptr<Node> &child : n->children) {
if (child->name == segment && child->isHighPriority == (priority == HIGH_PRIORITY)) {
if (((segment.length() && child->name.length() && segment[0] == ':' && child->name[0] == ':') || child->name == segment) && child->isHighPriority == (priority == HIGH_PRIORITY)) {
next = child.get();
break;
}
@@ -304,12 +304,19 @@ public:
for (auto &p : root.children) {
if (p->name == method) {
/* Then route the url */
return executeHandlers(p.get(), 0, userData);
if (executeHandlers(p.get(), 0, userData)) {
return true;
} else {
break;
}
}
}
/* We did not find any handler for this method and url */
return false;
/* Always test any route last (this check should not be necessary if we always have at least one handler) */
if (root.children.empty()) [[unlikely]] {
return false;
}
return executeHandlers(root.children.back().get(), 0, userData);
}
/* Adds the corresponding entires in matching tree and handler list */
@@ -379,11 +386,11 @@ public:
/* Removes ALL routes with the same handler as can be found with the given parameters.
* Removing a wildcard is done by removing ONE OF the methods the wildcard would match with.
* Example: If wildcard includes POST, GET, PUT, you can remove ALL THREE by removing GET. */
void remove(std::string method, std::string pattern, uint32_t priority) {
bool remove(std::string method, std::string pattern, uint32_t priority) {
uint32_t handler = findHandler(method, pattern, priority);
if (handler == UINT32_MAX) {
/* Not found or already removed, do nothing */
return;
return false;
}
/* Cull the entire tree */
@@ -394,6 +401,8 @@ public:
/* Now remove the actual handler */
handlers.erase(handlers.begin() + (handler & HANDLER_MASK));
return true;
}
};