aboutsummaryrefslogtreecommitdiff
path: root/src/httpserver.h
diff options
context:
space:
mode:
authorstickies-v <stickies-v@protonmail.com>2022-01-05 14:28:12 +0000
committerstickies-v <stickies-v@protonmail.com>2022-03-10 12:01:54 +0100
commita09497614e9bb603fff36286d9611a25b23eeb02 (patch)
treea1c484e29c8f7c32555b580bfbf44661aad6426b /src/httpserver.h
parentfff771ee864975cee8c831651239bac95503c37a (diff)
downloadbitcoin-a09497614e9bb603fff36286d9611a25b23eeb02.tar.xz
Add GetQueryParameter helper function
Easily get the query parameter from the URI, with optional default value.
Diffstat (limited to 'src/httpserver.h')
-rw-r--r--src/httpserver.h28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/httpserver.h b/src/httpserver.h
index 97cd63778a..4b60e74e19 100644
--- a/src/httpserver.h
+++ b/src/httpserver.h
@@ -5,8 +5,9 @@
#ifndef BITCOIN_HTTPSERVER_H
#define BITCOIN_HTTPSERVER_H
-#include <string>
#include <functional>
+#include <optional>
+#include <string>
static const int DEFAULT_HTTP_THREADS=4;
static const int DEFAULT_HTTP_WORKQUEUE=16;
@@ -83,6 +84,17 @@ public:
*/
RequestMethod GetRequestMethod() const;
+ /** Get the query parameter value from request uri for a specified key, or std::nullopt if the
+ * key is not found.
+ *
+ * If the query string contains duplicate keys, the first value is returned. Many web frameworks
+ * would instead parse this as an array of values, but this is not (yet) implemented as it is
+ * currently not needed in any of the endpoints.
+ *
+ * @param[in] key represents the query parameter of which the value is returned
+ */
+ std::optional<std::string> GetQueryParameter(const std::string& key) const;
+
/**
* Get the request header specified by hdr, or an empty string.
* Return a pair (isPresent,string).
@@ -115,6 +127,20 @@ public:
void WriteReply(int nStatus, const std::string& strReply = "");
};
+/** Get the query parameter value from request uri for a specified key, or std::nullopt if the key
+ * is not found.
+ *
+ * If the query string contains duplicate keys, the first value is returned. Many web frameworks
+ * would instead parse this as an array of values, but this is not (yet) implemented as it is
+ * currently not needed in any of the endpoints.
+ *
+ * Helper function for HTTPRequest::GetQueryParameter.
+ *
+ * @param[in] uri is the entire request uri
+ * @param[in] key represents the query parameter of which the value is returned
+ */
+std::optional<std::string> GetQueryParameterFromUri(const char* uri, const std::string& key);
+
/** Event handler closure.
*/
class HTTPClosure