summaryrefslogtreecommitdiff
path: root/crow
diff options
context:
space:
mode:
authorEd Tanous <ed.tanous@intel.com>2017-04-05 03:23:00 +0300
committerEd Tanous <ed.tanous@intel.com>2017-04-05 03:23:00 +0300
commitb4a7bfad0a3ded7a813bdb44a46383316dc49b24 (patch)
treeabb214b5a886744e942257641c2b60f7d97e4f15 /crow
parent1e94fa402ac5858329101e448593a0b61d24f765 (diff)
downloadbmcweb-b4a7bfad0a3ded7a813bdb44a46383316dc49b24.tar.xz
Add route printer
Diffstat (limited to 'crow')
-rw-r--r--crow/include/crow/app.h6
-rw-r--r--crow/include/crow/routing.h10
-rw-r--r--crow/include/crow/socket_adaptors.h26
3 files changed, 41 insertions, 1 deletions
diff --git a/crow/include/crow/app.h b/crow/include/crow/app.h
index 9162352f66..e0e5d84868 100644
--- a/crow/include/crow/app.h
+++ b/crow/include/crow/app.h
@@ -21,7 +21,7 @@
#define CROW_ROUTE(app, url) app.route_dynamic(url)
#else
#define CROW_ROUTE(app, url) \
- app.route<crow::black_magic::get_parameter_tag(url)>(url)
+ app.template route<crow::black_magic::get_parameter_tag(url)>(url)
#endif
namespace crow {
@@ -116,6 +116,10 @@ class Crow {
router_.debug_print();
}
+ std::vector<std::string> get_routes() {
+ return router_.get_routes();
+ }
+
#ifdef CROW_ENABLE_SSL
self_t& ssl_file(const std::string& crt_filename,
const std::string& key_filename) {
diff --git a/crow/include/crow/routing.h b/crow/include/crow/routing.h
index a82c34e111..d07f09f625 100644
--- a/crow/include/crow/routing.h
+++ b/crow/include/crow/routing.h
@@ -940,6 +940,16 @@ class Router {
void debug_print() { trie_.debug_print(); }
+ std::vector<std::string> get_routes() {
+ std::vector<std::string> ret;
+ for (auto& rule: rules_){
+ if (rule != nullptr){
+ ret.push_back(rule->rule_);
+ }
+ }
+ return ret;
+ }
+
private:
std::vector<std::unique_ptr<BaseRule>> rules_;
Trie trie_;
diff --git a/crow/include/crow/socket_adaptors.h b/crow/include/crow/socket_adaptors.h
index fe1bb9339e..a0d8dfa14c 100644
--- a/crow/include/crow/socket_adaptors.h
+++ b/crow/include/crow/socket_adaptors.h
@@ -33,6 +33,32 @@ struct SocketAdaptor {
tcp::socket socket_;
};
+
+struct TestSocketAdaptor {
+ using context = void;
+ TestSocketAdaptor(boost::asio::io_service& io_service, context*)
+ : socket_(io_service) {}
+
+ boost::asio::io_service& get_io_service() { return socket_.get_io_service(); }
+
+ tcp::socket& raw_socket() { return socket_; }
+
+ tcp::socket& socket() { return socket_; }
+
+ tcp::endpoint remote_endpoint() { return socket_.remote_endpoint(); }
+
+ bool is_open() { return socket_.is_open(); }
+
+ void close() { socket_.close(); }
+
+ template <typename F>
+ void start(F f) {
+ f(boost::system::error_code());
+ }
+
+ tcp::socket socket_;
+};
+
#ifdef CROW_ENABLE_SSL
struct SSLAdaptor {
using context = boost::asio::ssl::context;