httplib.h: use boost::regex, for some reasons as in 044ee8b32c87375fbd59735a13f082c8a037494e
这个提交包含在:
父节点
f992f4d20b
当前提交
f5b594449d
@ -1,6 +1,6 @@
|
||||
//
|
||||
// httplib.h
|
||||
//
|
||||
// Copyright (c) 2018 Albert S. All rights reserved.
|
||||
// Copyright (c) 2017 Yuji Hirose. All rights reserved.
|
||||
// MIT License
|
||||
//
|
||||
@ -59,7 +59,7 @@ typedef int socket_t;
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <regex>
|
||||
#include <boost/regex.hpp>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <sys/stat.h>
|
||||
@ -109,7 +109,7 @@ template <typename uint64_t, typename... Args>
|
||||
std::pair<std::string, std::string> make_range_header(uint64_t value, Args... args);
|
||||
|
||||
typedef std::multimap<std::string, std::string> Params;
|
||||
typedef std::smatch Match;
|
||||
typedef boost::smatch Match;
|
||||
typedef std::function<bool(uint64_t current, uint64_t total)> Progress;
|
||||
|
||||
struct MultipartFile
|
||||
@ -236,7 +236,7 @@ class Server
|
||||
size_t keep_alive_max_count_;
|
||||
|
||||
private:
|
||||
typedef std::vector<std::pair<std::regex, Handler>> Handlers;
|
||||
typedef std::vector<std::pair<boost::regex, Handler>> Handlers;
|
||||
|
||||
socket_t create_server_socket(const char *host, int port, int socket_flags) const;
|
||||
int bind_internal(const char *host, int port, int socket_flags);
|
||||
@ -744,9 +744,9 @@ inline void read_file(const std::string &path, std::string &out)
|
||||
|
||||
inline std::string file_extension(const std::string &path)
|
||||
{
|
||||
std::smatch m;
|
||||
auto pat = std::regex("\\.([a-zA-Z0-9]+)$");
|
||||
if(std::regex_search(path, m, pat))
|
||||
boost::smatch m;
|
||||
auto pat = boost::regex("\\.([a-zA-Z0-9]+)$");
|
||||
if(boost::regex_search(path, m, pat))
|
||||
{
|
||||
return m[1].str();
|
||||
}
|
||||
@ -866,7 +866,7 @@ inline int get_header_value_int(const Headers &headers, const char *key, int def
|
||||
|
||||
inline bool read_headers(Stream &strm, Headers &headers)
|
||||
{
|
||||
static std::regex re(R"((.+?):\s*(.+?)\s*\r\n)");
|
||||
static boost::regex re(R"((.+?):\s*(.+?)\s*\r\n)");
|
||||
|
||||
const auto bufsiz = 2048;
|
||||
char buf[bufsiz];
|
||||
@ -883,8 +883,8 @@ inline bool read_headers(Stream &strm, Headers &headers)
|
||||
{
|
||||
break;
|
||||
}
|
||||
std::cmatch m;
|
||||
if(std::regex_match(reader.ptr(), m, re))
|
||||
boost::cmatch m;
|
||||
if(boost::regex_match(reader.ptr(), m, re))
|
||||
{
|
||||
auto key = std::string(m[1]);
|
||||
auto val = std::string(m[2]);
|
||||
@ -1267,10 +1267,10 @@ inline bool parse_multipart_formdata(const std::string &boundary, const std::str
|
||||
static std::string dash = "--";
|
||||
static std::string crlf = "\r\n";
|
||||
|
||||
static std::regex re_content_type("Content-Type: (.*?)", std::regex_constants::icase);
|
||||
static boost::regex re_content_type("Content-Type: (.*?)", boost::regex_constants::icase);
|
||||
|
||||
static std::regex re_content_disposition("Content-Disposition: form-data; name=\"(.*?)\"(?:; filename=\"(.*?)\")?",
|
||||
std::regex_constants::icase);
|
||||
static boost::regex re_content_disposition(
|
||||
"Content-Disposition: form-data; name=\"(.*?)\"(?:; filename=\"(.*?)\")?", boost::regex_constants::icase);
|
||||
|
||||
auto dash_boundary = dash + boundary;
|
||||
|
||||
@ -1305,12 +1305,12 @@ inline bool parse_multipart_formdata(const std::string &boundary, const std::str
|
||||
|
||||
while(pos != next_pos)
|
||||
{
|
||||
std::smatch m;
|
||||
if(std::regex_match(header, m, re_content_type))
|
||||
boost::smatch m;
|
||||
if(boost::regex_match(header, m, re_content_type))
|
||||
{
|
||||
file.content_type = m[1];
|
||||
}
|
||||
else if(std::regex_match(header, m, re_content_disposition))
|
||||
else if(boost::regex_match(header, m, re_content_disposition))
|
||||
{
|
||||
name = m[1];
|
||||
file.filename = m[2];
|
||||
@ -1658,31 +1658,31 @@ inline Server::~Server()
|
||||
|
||||
inline Server &Server::Get(const char *pattern, Handler handler)
|
||||
{
|
||||
get_handlers_.push_back(std::make_pair(std::regex(pattern), handler));
|
||||
get_handlers_.push_back(std::make_pair(boost::regex(pattern), handler));
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Server &Server::Post(const char *pattern, Handler handler)
|
||||
{
|
||||
post_handlers_.push_back(std::make_pair(std::regex(pattern), handler));
|
||||
post_handlers_.push_back(std::make_pair(boost::regex(pattern), handler));
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Server &Server::Put(const char *pattern, Handler handler)
|
||||
{
|
||||
put_handlers_.push_back(std::make_pair(std::regex(pattern), handler));
|
||||
put_handlers_.push_back(std::make_pair(boost::regex(pattern), handler));
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Server &Server::Delete(const char *pattern, Handler handler)
|
||||
{
|
||||
delete_handlers_.push_back(std::make_pair(std::regex(pattern), handler));
|
||||
delete_handlers_.push_back(std::make_pair(boost::regex(pattern), handler));
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Server &Server::Options(const char *pattern, Handler handler)
|
||||
{
|
||||
options_handlers_.push_back(std::make_pair(std::regex(pattern), handler));
|
||||
options_handlers_.push_back(std::make_pair(boost::regex(pattern), handler));
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -1747,10 +1747,10 @@ inline void Server::stop()
|
||||
|
||||
inline bool Server::parse_request_line(const char *s, Request &req)
|
||||
{
|
||||
static std::regex re("(GET|HEAD|POST|PUT|DELETE|OPTIONS) (([^?]+)(?:\\?(.+?))?) (HTTP/1\\.[01])\r\n");
|
||||
static boost::regex re("(GET|HEAD|POST|PUT|DELETE|OPTIONS) (([^?]+)(?:\\?(.+?))?) (HTTP/1\\.[01])\r\n");
|
||||
|
||||
std::cmatch m;
|
||||
if(std::regex_match(s, m, re))
|
||||
boost::cmatch m;
|
||||
if(boost::regex_match(s, m, re))
|
||||
{
|
||||
req.version = std::string(m[5]);
|
||||
req.method = std::string(m[1]);
|
||||
@ -2046,7 +2046,7 @@ inline bool Server::dispatch_request(Request &req, Response &res, Handlers &hand
|
||||
const auto &pattern = x.first;
|
||||
const auto &handler = x.second;
|
||||
|
||||
if(std::regex_match(req.path, req.matches, pattern))
|
||||
if(boost::regex_match(req.path, req.matches, pattern))
|
||||
{
|
||||
handler(req, res);
|
||||
return true;
|
||||
@ -2204,10 +2204,10 @@ inline bool Client::read_response_line(Stream &strm, Response &res)
|
||||
return false;
|
||||
}
|
||||
|
||||
const static std::regex re("(HTTP/1\\.[01]) (\\d+?) .+\r\n");
|
||||
const static boost::regex re("(HTTP/1\\.[01]) (\\d+?) .+\r\n");
|
||||
|
||||
std::cmatch m;
|
||||
if(std::regex_match(reader.ptr(), m, re))
|
||||
boost::cmatch m;
|
||||
if(boost::regex_match(reader.ptr(), m, re))
|
||||
{
|
||||
res.version = std::string(m[1]);
|
||||
res.status = std::stoi(std::string(m[2]));
|
||||
|
正在加载...
在新工单中引用
屏蔽一个用户