diff --git a/src/oatpp/web/protocol/http/Http.cpp b/src/oatpp/web/protocol/http/Http.cpp index caa35217..0ddcc090 100644 --- a/src/oatpp/web/protocol/http/Http.cpp +++ b/src/oatpp/web/protocol/http/Http.cpp @@ -351,4 +351,21 @@ void Parser::parseHeaders(Headers& headers, } +std::unordered_set Parser::parseHeaderValueSet(const oatpp::data::share::StringKeyLabel& headerValue, char separator) { + + std::unordered_set result; + oatpp::parser::Caret caret(headerValue.getData(), headerValue.getSize()); + + while (caret.canContinue()) { + caret.skipChar(' '); // skip leading space + auto label = caret.putLabel(); + caret.findChar(separator); // find separator char, or end of the header value + result.insert(oatpp::data::share::StringKeyLabelCI(headerValue.getMemoryHandle(), label.getData(), label.getSize())); + caret.inc(); + } + + return result; + +} + }}}} diff --git a/src/oatpp/web/protocol/http/Http.hpp b/src/oatpp/web/protocol/http/Http.hpp index 94cddb08..58e42909 100644 --- a/src/oatpp/web/protocol/http/Http.hpp +++ b/src/oatpp/web/protocol/http/Http.hpp @@ -36,6 +36,7 @@ #include "oatpp/core/Types.hpp" #include +#include namespace oatpp { namespace web { namespace protocol { namespace http { @@ -650,6 +651,14 @@ public: const std::shared_ptr& headersText, oatpp::parser::Caret& caret, Status& error); + + /** + * Parse header value separated by `char separator`. + * @param headerValue - value of the header. + * @param separator - separator char. + * @return - `std::unordered_set` of &id:oatpp::data::share::StringKeyLabelCI;. + */ + static std::unordered_set parseHeaderValueSet(const oatpp::data::share::StringKeyLabel& headerValue, char separator); }; diff --git a/test/oatpp/web/FullTest.cpp b/test/oatpp/web/FullTest.cpp index cfb8b974..59ee72fa 100644 --- a/test/oatpp/web/FullTest.cpp +++ b/test/oatpp/web/FullTest.cpp @@ -50,7 +50,7 @@ namespace oatpp { namespace test { namespace web { namespace { -//#define OATPP_TEST_USE_PORT 8123 +//#define OATPP_TEST_USE_PORT 8000 class TestComponent { public: @@ -180,6 +180,11 @@ void FullTest::onRun() { OATPP_ASSERT(returnedData == data); } + { + auto response = client->headerValueSet(" VALUE_1, VALUE_2, VALUE_3", connection); + OATPP_ASSERT(response->getStatusCode() == 200); + } + if((i + 1) % iterationsStep == 0) { OATPP_LOGD("i", "%d", i + 1); } diff --git a/test/oatpp/web/app/Client.hpp b/test/oatpp/web/app/Client.hpp index 14efb5ac..8b37a75a 100644 --- a/test/oatpp/web/app/Client.hpp +++ b/test/oatpp/web/app/Client.hpp @@ -42,6 +42,8 @@ class Client : public oatpp::web::client::ApiClient { API_CALL("GET", "headers", getWithHeaders, HEADER(String, param, "X-TEST-HEADER")) API_CALL("POST", "body", postBody, BODY_STRING(String, body)) API_CALL("POST", "echo", echoBody, BODY_STRING(String, body)) + + API_CALL("GET", "header-value-set", headerValueSet, HEADER(String, valueSet, "X-VALUE-SET")) #include OATPP_CODEGEN_END(ApiClient) }; diff --git a/test/oatpp/web/app/Controller.hpp b/test/oatpp/web/app/Controller.hpp index 5b5c07bd..2ee991d8 100644 --- a/test/oatpp/web/app/Controller.hpp +++ b/test/oatpp/web/app/Controller.hpp @@ -103,6 +103,15 @@ public: return createResponse(Status::CODE_200, body); } + ENDPOINT("GET", "header-value-set", headerValueSet, + HEADER(String, valueSet, "X-VALUE-SET")) { + auto set = oatpp::web::protocol::http::Parser::parseHeaderValueSet(valueSet, ','); + OATPP_ASSERT_HTTP(set.find("VALUE_1") != set.end(), Status::CODE_400, "No header 'VALUE_1' in value set"); + OATPP_ASSERT_HTTP(set.find("VALUE_2") != set.end(), Status::CODE_400, "No header 'VALUE_2' in value set"); + OATPP_ASSERT_HTTP(set.find("VALUE_3") != set.end(), Status::CODE_400, "No header 'VALUE_3' in value set"); + return createResponse(Status::CODE_200, ""); + } + #include OATPP_CODEGEN_END(ApiController) };