Add QueryParser.h for decoding URI queries by key

This commit is contained in:
Alex Hultman
2020-09-28 12:15:01 +02:00
parent 270308f104
commit a1445d9459
2 changed files with 123 additions and 0 deletions
+10
View File
@@ -29,6 +29,7 @@
#include "BloomFilter.h"
#include "ProxyParser.h"
#include "QueryParser.h"
namespace uWS {
@@ -108,6 +109,7 @@ public:
return std::string_view(headers->key.data(), headers->key.length());
}
/* Returns the raw querystring as a whole, still encoded */
std::string_view getQuery() {
if (querySeparator < (int) headers->value.length()) {
/* Strip the initial ? */
@@ -117,6 +119,14 @@ public:
}
}
/* Finds and decodes the URI component. */
std::string_view getQuery(std::string_view key) {
/* Raw querystring including initial '?' sign */
std::string_view queryString = std::string_view(headers->value.data() + querySeparator, headers->value.length() - querySeparator);
return getDecodedQueryValue(key, queryString);
}
void setParameters(std::pair<int, std::string_view *> parameters) {
currentParameters = parameters;
}