From 3c4c3786557ba5aef2206f7daaa815a43fe68eed Mon Sep 17 00:00:00 2001 From: eidheim Date: Wed, 24 Feb 2016 09:13:23 +0100 Subject: [PATCH] Fixes #35 for both client and server source --- client_http.hpp | 26 ++++++++++++++++++++++---- server_http.hpp | 22 ++++++++++++++++++++-- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/client_http.hpp b/client_http.hpp index c400152..cf62b52 100644 --- a/client_http.hpp +++ b/client_http.hpp @@ -3,6 +3,8 @@ #include #include +#include +#include #include #include @@ -15,12 +17,27 @@ namespace SimpleWeb { class Response { friend class ClientBase; + class iequal_to { + public: + bool operator()(const std::string &key1, const std::string &key2) const { + return boost::algorithm::iequals(key1, key2); + } + }; + class ihash { + public: + size_t operator()(const std::string &key) const { + std::size_t seed=0; + for(auto &c: key) + boost::hash_combine(seed, std::tolower(c)); + return seed; + } + }; public: std::string http_version, status_code; std::istream content; - std::unordered_map header; + std::unordered_multimap header; private: boost::asio::streambuf content_buffer; @@ -161,14 +178,15 @@ namespace SimpleWeb { parse_response_header(response, response->content); - if(response->header.count("Content-Length")>0) { - auto content_length=stoull(response->header["Content-Length"]); + auto header_it=response->header.find("Content-Length"); + if(header_it!=response->header.end()) { + auto content_length=stoull(header_it->second); if(content_length>num_additional_bytes) { boost::asio::read(*socket, response->content_buffer, boost::asio::transfer_exactly(content_length-num_additional_bytes)); } } - else if(response->header.count("Transfer-Encoding")>0 && response->header["Transfer-Encoding"]=="chunked") { + else if((header_it=response->header.find("Transfer-Encoding"))!=response->header.end() && header_it->second=="chunked") { boost::asio::streambuf streambuf; std::ostream content(&streambuf); diff --git a/server_http.hpp b/server_http.hpp index 47e1963..84e9d8b 100644 --- a/server_http.hpp +++ b/server_http.hpp @@ -4,6 +4,8 @@ #include #include #include +#include +#include #include #include @@ -58,12 +60,28 @@ namespace SimpleWeb { class Request { friend class ServerBase; + + class iequal_to { + public: + bool operator()(const std::string &key1, const std::string &key2) const { + return boost::algorithm::iequals(key1, key2); + } + }; + class ihash { + public: + size_t operator()(const std::string &key) const { + std::size_t seed=0; + for(auto &c: key) + boost::hash_combine(seed, std::tolower(c)); + return seed; + } + }; public: std::string method, path, http_version; Content content; - std::unordered_multimap header; + std::unordered_multimap header; boost::smatch path_match; @@ -236,7 +254,7 @@ namespace SimpleWeb { parse_request(request, request->content); //If content, read that as well - const auto it=request->header.find("Content-Length"); + auto it=request->header.find("Content-Length"); if(it!=request->header.end()) { //Set timeout on the following boost::asio::async-read or write function std::shared_ptr timer;