|
5 | 5 | #ifndef BITCOIN_HTTPSERVER_H |
6 | 6 | #define BITCOIN_HTTPSERVER_H |
7 | 7 |
|
8 | | -#include <string> |
9 | 8 | #include <functional> |
| 9 | +#include <optional> |
| 10 | +#include <string> |
10 | 11 |
|
11 | 12 | static const int DEFAULT_HTTP_THREADS=4; |
12 | 13 | static const int DEFAULT_HTTP_WORKQUEUE=16; |
@@ -82,6 +83,17 @@ class HTTPRequest |
82 | 83 | */ |
83 | 84 | RequestMethod GetRequestMethod() const; |
84 | 85 |
|
| 86 | + /** Get the query parameter value from request uri for a specified key, or std::nullopt if the |
| 87 | + * key is not found. |
| 88 | + * |
| 89 | + * If the query string contains duplicate keys, the first value is returned. Many web frameworks |
| 90 | + * would instead parse this as an array of values, but this is not (yet) implemented as it is |
| 91 | + * currently not needed in any of the endpoints. |
| 92 | + * |
| 93 | + * @param[in] key represents the query parameter of which the value is returned |
| 94 | + */ |
| 95 | + std::optional<std::string> GetQueryParameter(const std::string& key) const; |
| 96 | + |
85 | 97 | /** |
86 | 98 | * Get the request header specified by hdr, or an empty string. |
87 | 99 | * Return a pair (isPresent,string). |
@@ -114,6 +126,20 @@ class HTTPRequest |
114 | 126 | void WriteReply(int nStatus, const std::string& strReply = ""); |
115 | 127 | }; |
116 | 128 |
|
| 129 | +/** Get the query parameter value from request uri for a specified key, or std::nullopt if the key |
| 130 | + * is not found. |
| 131 | + * |
| 132 | + * If the query string contains duplicate keys, the first value is returned. Many web frameworks |
| 133 | + * would instead parse this as an array of values, but this is not (yet) implemented as it is |
| 134 | + * currently not needed in any of the endpoints. |
| 135 | + * |
| 136 | + * Helper function for HTTPRequest::GetQueryParameter. |
| 137 | + * |
| 138 | + * @param[in] uri is the entire request uri |
| 139 | + * @param[in] key represents the query parameter of which the value is returned |
| 140 | + */ |
| 141 | +std::optional<std::string> GetQueryParameterFromUri(const char* uri, const std::string& key); |
| 142 | + |
117 | 143 | /** Event handler closure. |
118 | 144 | */ |
119 | 145 | class HTTPClosure |
|
0 commit comments