Skip to content
Snippets Groups Projects
Verified Commit 8d0abb4d authored by Nicolas Werner's avatar Nicolas Werner
Browse files

Make headers case insensitive

parent ab7d5a8f
No related branches found
No related tags found
No related merge requests found
Pipeline #1279 failed
......@@ -14,12 +14,12 @@
#include <event2/event_struct.h>
#include <spdlog/logger.h>
#include "headers.hpp"
namespace coeurl {
struct Request;
struct SockInfo;
using Headers = std::map<std::string, std::string>;
/* Global information, common to all connections */
struct Client {
Client();
......
#pragma once
#include <string>
#include <map>
namespace coeurl {
struct header_less {
bool operator()(const std::string &, const std::string &) const;
};
using Headers = std::map<std::string, std::string, header_less>;
} // namespace coeurl
......@@ -42,13 +42,25 @@ static std::string_view trim(std::string_view val) {
return val;
}
static std::string ascii_lower(std::string_view val) {
std::string ret = std::string(val);
for (auto &c : ret) {
if (c >= 'A' && c <= 'Z')
c |= 0b00100000;
static char ascii_lower(char c) {
if (c >= 'A' && c <= 'Z')
c |= 0b00100000;
return c;
}
bool header_less::operator()(const std::string &a, const std::string &b) const {
if (a.size() != b.size())
return a.size() < b.size();
for (size_t i = 0; i < a.size(); i++) {
auto a_c = ascii_lower(a[i]);
auto b_c = ascii_lower(b[i]);
if (a_c != b_c)
return a_c < b_c;
}
return ret;
return false;
}
/* CURLOPT_HEADERFUNCTION */
......@@ -62,7 +74,7 @@ size_t Request::header_cb(char *buffer, size_t, size_t nitems, void *data) {
Client::log->debug("Header: {} ({}: {})", request->url_, key, val);
request->response_headers_.insert({ascii_lower(key), std::string(val)});
request->response_headers_.insert({std::string(key), std::string(val)});
}
return nitems;
......
......@@ -23,7 +23,7 @@ lib = library('coeurl', ['lib/client.cpp', 'lib/request.cpp'],
dependencies: deps,
install : true)
install_headers('include/coeurl/client.hpp', 'include/coeurl/request.hpp', subdir : 'coeurl')
install_headers('include/coeurl/headers.hpp', 'include/coeurl/client.hpp', 'include/coeurl/request.hpp', subdir : 'coeurl')
dep = declare_dependency(include_directories: include, link_with: lib, dependencies: deps)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment