mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 06:28:31 +01:00
Add GetQueryParameter helper function
Easily get the query parameter from the URI, with optional default value.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user