# HG changeset patch # User František Kučera # Date 1647982859 -3600 # Node ID d8efcefdf9062717430eb30ad2a65fff421c0d1a # Parent aa43616375c61ec2d0420c646362acf55f62e6ab support common-header filtering by URL regex patterns diff -r aa43616375c6 -r d8efcefdf906 src/HTTPHandler.h --- 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 #include #include +#include #include #include @@ -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> 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 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;