--- a/src/HTTPHandler.h Tue Mar 22 01:19:21 2022 +0100
+++ b/src/HTTPHandler.h Tue Mar 22 22:00:59 2022 +0100
@@ -21,6 +21,7 @@
#include <vector>
#include <codecvt>
#include <regex>
+#include <locale>
#include <stdexcept>
#include <curl/curl.h>
@@ -47,9 +48,13 @@
class HeaderDefinition {
public:
- // TODO: filters/patterns/condition
+ std::wregex url = std::wregex(L".*");
relpipe::common::type::StringX name;
relpipe::common::type::StringX value;
+
+ bool matches(const relpipe::common::type::StringX& url) const {
+ return std::regex_match(url, this->url);
+ }
};
std::wstring_convert<codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings.
@@ -150,6 +155,7 @@
if (attributeName == L"name") requestHeader.name = value;
else if (attributeName == L"value") requestHeader.value = value;
+ else if (attributeName == L"url") requestHeader.url = std::wregex(value.size() ? value : L".*"); // TODO: null instead of empty value (when supported)
else throw std::invalid_argument("Unsupported attribute in the header relation: " + convertor.to_bytes(attributeName + L" = " + value));
currentAttributeIndex++;
@@ -176,7 +182,7 @@
currentAttributeIndex = 0;
std::shared_ptr<HTTPClient> http(HTTPClient::open());
- for (const HeaderDefinition& h : requestHeaders) appendRequestHeader(h.name, h.value);
+ for (const HeaderDefinition& h : requestHeaders) if (h.matches(convertor.from_bytes(request.url))) appendRequestHeader(h.name, h.value);
std::string body;
relpipe::common::type::Integer responseCode = -1;