@@ -73,9 +73,25 @@ typedef int socket_t;
73
73
namespace httplib
74
74
{
75
75
76
+ namespace detail {
77
+
78
+ struct ci {
79
+ bool operator () (const std::string & s1, const std::string & s2) const {
80
+ return std::lexicographical_compare (
81
+ s1.begin (), s1.end (),
82
+ s2.begin (), s2.end (),
83
+ [](char c1, char c2) {
84
+ return std::tolower (c1) < std::tolower (c2);
85
+ });
86
+ }
87
+ };
88
+
89
+ } // namespace detail
90
+
76
91
enum class HttpVersion { v1_0 = 0 , v1_1 };
77
92
78
- typedef std::multimap<std::string, std::string> MultiMap;
93
+ typedef std::multimap<std::string, std::string, detail::ci> Headers;
94
+ typedef std::multimap<std::string, std::string> Params;
79
95
typedef std::smatch Match;
80
96
typedef std::function<void (int64_t current, int64_t total)> Progress;
81
97
@@ -90,9 +106,9 @@ typedef std::multimap<std::string, MultipartFile> MultipartFiles;
90
106
struct Request {
91
107
std::string method;
92
108
std::string path;
93
- MultiMap headers;
109
+ Headers headers;
94
110
std::string body;
95
- MultiMap params;
111
+ Params params;
96
112
MultipartFiles files;
97
113
Match matches;
98
114
Progress progress;
@@ -110,7 +126,7 @@ struct Request {
110
126
111
127
struct Response {
112
128
int status;
113
- MultiMap headers;
129
+ Headers headers;
114
130
std::string body;
115
131
116
132
bool has_header (const char * key) const ;
@@ -198,7 +214,7 @@ class Client {
198
214
std::shared_ptr<Response> get (const char * path, Progress callback = [](int64_t ,int64_t ){});
199
215
std::shared_ptr<Response> head (const char * path);
200
216
std::shared_ptr<Response> post (const char * path, const std::string& body, const char * content_type);
201
- std::shared_ptr<Response> post (const char * path, const MultiMap & params);
217
+ std::shared_ptr<Response> post (const char * path, const Params & params);
202
218
203
219
bool send (const Request& req, Response& res);
204
220
@@ -562,7 +578,7 @@ inline const char* status_message(int status)
562
578
}
563
579
}
564
580
565
- inline const char * get_header_value (const MultiMap & headers, const char * key, const char * def)
581
+ inline const char * get_header_value (const Headers & headers, const char * key, const char * def)
566
582
{
567
583
auto it = headers.find (key);
568
584
if (it != headers.end ()) {
@@ -571,7 +587,7 @@ inline const char* get_header_value(const MultiMap& headers, const char* key, co
571
587
return def;
572
588
}
573
589
574
- inline int get_header_value_int (const MultiMap & headers, const char * key, int def)
590
+ inline int get_header_value_int (const Headers & headers, const char * key, int def)
575
591
{
576
592
auto it = headers.find (key);
577
593
if (it != headers.end ()) {
@@ -580,7 +596,7 @@ inline int get_header_value_int(const MultiMap& headers, const char* key, int de
580
596
return def;
581
597
}
582
598
583
- inline bool read_headers (Stream& strm, MultiMap & headers)
599
+ inline bool read_headers (Stream& strm, Headers & headers)
584
600
{
585
601
static std::regex re (" (.+?): (.+?)\r\n " );
586
602
@@ -853,7 +869,7 @@ inline std::string decode_url(const std::string& s)
853
869
return result;
854
870
}
855
871
856
- inline void parse_query_text (const std::string& s, MultiMap & params)
872
+ inline void parse_query_text (const std::string& s, Params & params)
857
873
{
858
874
split (&s[0 ], &s[s.size ()], ' &' , [&](const char * b, const char * e) {
859
875
std::string key;
@@ -980,6 +996,17 @@ class WSInit {
980
996
static WSInit wsinit_;
981
997
#endif
982
998
999
+ inline std::string to_lower (const char * beg, const char * end)
1000
+ {
1001
+ std::string out;
1002
+ auto it = beg;
1003
+ while (it != end) {
1004
+ out += ::tolower (*it);
1005
+ it++;
1006
+ }
1007
+ return out;
1008
+ }
1009
+
983
1010
} // namespace detail
984
1011
985
1012
// Request implementation
@@ -1497,7 +1524,7 @@ inline std::shared_ptr<Response> Client::post(
1497
1524
}
1498
1525
1499
1526
inline std::shared_ptr<Response> Client::post (
1500
- const char * path, const MultiMap & params)
1527
+ const char * path, const Params & params)
1501
1528
{
1502
1529
std::string query;
1503
1530
for (auto it = params.begin (); it != params.end (); ++it) {
0 commit comments