From d1573c6218c073ef930f183372dcd4a6c1a42420 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Fri, 4 Sep 2020 02:29:26 +0100 Subject: [PATCH] Header entries should be case insensitive --- src/oro/api_nap.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/oro/api_nap.cpp b/src/oro/api_nap.cpp index 62d5564..72b14f4 100644 --- a/src/oro/api_nap.cpp +++ b/src/oro/api_nap.cpp @@ -21,6 +21,8 @@ #include "duckhandy/int_conv.hpp" #include "api_nap_exception.hpp" #include +#include +#include namespace sjd = simdjson::dom; namespace sj = simdjson; @@ -28,22 +30,30 @@ namespace sj = simdjson; namespace oro { namespace { +bool equal (std::string_view a, std::string_view b) { + return a.size() == b.size() and std::equal( + a.begin(), a.end(), + b.begin(), + [](auto c1, auto c2) {return std::tolower(c1) == std::tolower(c2); } + ); +} + Header to_header (const nap::HttpResponse& resp) { using dhandy::int_conv; Header ret; for (const auto& entry : resp.header) { - if (entry.first == "Date") + if (equal(entry.first, "Date")) ret.date = from_header_timestamp(std::string(entry.second)); - else if (entry.first == "X-RateLimit-Limit") + else if (equal(entry.first, "X-RateLimit-Limit")) ret.rate_limit = int_conv(entry.second); - else if (entry.first == "X-RateLimit-Remaining") + else if (equal(entry.first, "X-RateLimit-Remaining")) ret.rate_limit_remaining = int_conv(entry.second); - else if (entry.first == "X-RateLimit-Reset") + else if (equal(entry.first, "X-RateLimit-Reset")) ret.rate_limit_reset = int_conv(entry.second); - else if (entry.first == "Retry-After") + else if (equal(entry.first, "Retry-After")) ret.retry_after = int_conv(entry.second); - else if (entry.first == "Server") + else if (equal(entry.first, "Server")) ret.server = std::string(entry.second); } return ret;