Added fallback to boost::regex if gcc version<4.9. Fixes #77
This commit is contained in:
parent
88a8b154e5
commit
8e0d3142bf
2 changed files with 23 additions and 7 deletions
|
|
@ -6,7 +6,15 @@ include_directories(.)
|
||||||
|
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
|
|
||||||
find_package(Boost 1.53.0 COMPONENTS system thread filesystem date_time REQUIRED)
|
set(BOOST_COMPONENTS system thread filesystem date_time)
|
||||||
|
# Late 2017 TODO: remove the following checks and always use std::regex
|
||||||
|
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||||
|
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)
|
||||||
|
set(BOOST_COMPONENTS ${BOOST_COMPONENTS} regex)
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_BOOST_REGEX")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
find_package(Boost 1.53.0 COMPONENTS ${BOOST_COMPONENTS} REQUIRED)
|
||||||
include_directories(SYSTEM ${Boost_INCLUDE_DIR})
|
include_directories(SYSTEM ${Boost_INCLUDE_DIR})
|
||||||
|
|
||||||
if(APPLE)
|
if(APPLE)
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,20 @@
|
||||||
#include <boost/functional/hash.hpp>
|
#include <boost/functional/hash.hpp>
|
||||||
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <regex>
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
// Late 2017 TODO: remove the following checks and always use std::regex
|
||||||
|
#ifdef USE_BOOST_REGEX
|
||||||
|
#include <boost/regex.hpp>
|
||||||
|
#define REGEX_NS boost
|
||||||
|
#else
|
||||||
|
#include <regex>
|
||||||
|
#define REGEX_NS std
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace SimpleWeb {
|
namespace SimpleWeb {
|
||||||
template <class socket_type>
|
template <class socket_type>
|
||||||
class ServerBase {
|
class ServerBase {
|
||||||
|
|
@ -75,7 +83,7 @@ namespace SimpleWeb {
|
||||||
|
|
||||||
std::unordered_multimap<std::string, std::string, ihash, iequal_to> header;
|
std::unordered_multimap<std::string, std::string, ihash, iequal_to> header;
|
||||||
|
|
||||||
std::smatch path_match;
|
REGEX_NS::smatch path_match;
|
||||||
|
|
||||||
std::string remote_endpoint_address;
|
std::string remote_endpoint_address;
|
||||||
unsigned short remote_endpoint_port;
|
unsigned short remote_endpoint_port;
|
||||||
|
|
@ -111,7 +119,7 @@ namespace SimpleWeb {
|
||||||
std::function<void(const std::exception&)> exception_handler;
|
std::function<void(const std::exception&)> exception_handler;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::pair<std::string, std::vector<std::pair<std::regex,
|
std::vector<std::pair<std::string, std::vector<std::pair<REGEX_NS::regex,
|
||||||
std::function<void(std::shared_ptr<typename ServerBase<socket_type>::Response>, std::shared_ptr<typename ServerBase<socket_type>::Request>)> > > > > opt_resource;
|
std::function<void(std::shared_ptr<typename ServerBase<socket_type>::Response>, std::shared_ptr<typename ServerBase<socket_type>::Request>)> > > > > opt_resource;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
@ -132,7 +140,7 @@ namespace SimpleWeb {
|
||||||
it=opt_resource.begin()+(opt_resource.size()-1);
|
it=opt_resource.begin()+(opt_resource.size()-1);
|
||||||
it->first=res_method.first;
|
it->first=res_method.first;
|
||||||
}
|
}
|
||||||
it->second.emplace_back(std::regex(res.first), res_method.second);
|
it->second.emplace_back(REGEX_NS::regex(res.first), res_method.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -335,8 +343,8 @@ namespace SimpleWeb {
|
||||||
for(auto& res: opt_resource) {
|
for(auto& res: opt_resource) {
|
||||||
if(request->method==res.first) {
|
if(request->method==res.first) {
|
||||||
for(auto& res_path: res.second) {
|
for(auto& res_path: res.second) {
|
||||||
std::smatch sm_res;
|
REGEX_NS::smatch sm_res;
|
||||||
if(std::regex_match(request->path, sm_res, res_path.first)) {
|
if(REGEX_NS::regex_match(request->path, sm_res, res_path.first)) {
|
||||||
request->path_match=std::move(sm_res);
|
request->path_match=std::move(sm_res);
|
||||||
write_response(socket, request, res_path.second);
|
write_response(socket, request, res_path.second);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue