Fix URL query separation
This commit is contained in:
@@ -71,14 +71,13 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
uWS::App a; // or uWS::SSLApp(options) for SSL
|
uWS::App a; // or uWS::SSLApp(options) for SSL
|
||||||
|
|
||||||
a/*.onGet("/", [](auto *s, auto *req, auto *args) {
|
a.onGet("/", [](auto *s, auto *req, auto *args) {
|
||||||
std::cout << "URL: /" << std::endl;
|
|
||||||
std::cout << "user-agent: " << req->getHeader("user-agent") << std::endl;
|
|
||||||
|
|
||||||
std::cout << "upgrade: " << req->getHeader("upgrade") << std::endl;
|
std::cout << "URL: <" << req->getUrl() << ">" << std::endl;
|
||||||
|
std::cout << "Query: <" << req->getQuery() << ">" << std::endl;
|
||||||
|
std::cout << "User-Agent: <" << req->getHeader("user-agent") << ">" << std::endl;
|
||||||
|
|
||||||
|
}).onWebSocket<UserData>("/ws", [](auto *ws, auto *req, auto *args) {
|
||||||
})*/.onWebSocket<UserData>("/", [](auto *ws, auto *req, auto *args) {
|
|
||||||
|
|
||||||
std::cout << "WebSocket connected to /wsApi" << std::endl;
|
std::cout << "WebSocket connected to /wsApi" << std::endl;
|
||||||
|
|
||||||
|
|||||||
+15
-1
@@ -14,6 +14,7 @@ private:
|
|||||||
struct Header {
|
struct Header {
|
||||||
std::string_view key, value;
|
std::string_view key, value;
|
||||||
} headers[MAX_HEADERS];
|
} headers[MAX_HEADERS];
|
||||||
|
int querySeparator;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::string_view getHeader(std::string_view header) {
|
std::string_view getHeader(std::string_view header) {
|
||||||
@@ -25,8 +26,17 @@ public:
|
|||||||
return std::string_view(nullptr, 0);
|
return std::string_view(nullptr, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo: implement this
|
||||||
|
int getHeader(std::string_view header) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
std::string_view getUrl() {
|
std::string_view getUrl() {
|
||||||
return headers->value;
|
return std::string_view(headers->value.data(), querySeparator);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string_view getQuery() {
|
||||||
|
return std::string_view(headers->value.data() + querySeparator, headers->value.length() - querySeparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -89,6 +99,10 @@ private:
|
|||||||
|
|
||||||
req->headers->value = std::string_view(req->headers->value.data(), std::max<int>(0, req->headers->value.length() - 9));
|
req->headers->value = std::string_view(req->headers->value.data(), std::max<int>(0, req->headers->value.length() - 9));
|
||||||
|
|
||||||
|
// querySeparator is untested, todo: go through this
|
||||||
|
const char *querySeparatorPtr = (const char *) memchr(req->headers->value.data(), '?', req->headers->value.length());
|
||||||
|
req->querySeparator = (querySeparatorPtr ? querySeparatorPtr : req->headers->value.data() + req->headers->value.length()) - req->headers->value.data();
|
||||||
|
|
||||||
requestHandler(user, req);
|
requestHandler(user, req);
|
||||||
|
|
||||||
std::string_view contentLengthString = req->getHeader("content-length");
|
std::string_view contentLengthString = req->getHeader("content-length");
|
||||||
|
|||||||
Reference in New Issue
Block a user