Rename namespace

This commit is contained in:
bugdea1er 2024-05-01 20:14:04 +03:00
parent 536fedead9
commit 87a7be0658
32 changed files with 257 additions and 257 deletions

View File

@ -67,7 +67,7 @@
* This is the recommended way to define routes in a crow application.
* \see [Page of guide "Routes"](https://crowcpp.org/master/guides/routes/).
*/
#define CROW_ROUTE(app, url) app.template route<crow::black_magic::get_parameter_tag(url)>(url)
#define CROW_ROUTE(app, url) app.template route<::http::black_magic::get_parameter_tag(url)>(url)
/**
* \def CROW_BP_ROUTE(blueprint, url)
@ -91,7 +91,7 @@
*
* \see [Page of the guide "Blueprints"](https://crowcpp.org/master/guides/blueprints/).
*/
#define CROW_BP_ROUTE(blueprint, url) blueprint.new_rule_tagged<crow::black_magic::get_parameter_tag(url)>(url)
#define CROW_BP_ROUTE(blueprint, url) blueprint.new_rule_tagged<::http::black_magic::get_parameter_tag(url)>(url)
/**
* \def CROW_WEBSOCKET_ROUTE(app, url)
@ -120,7 +120,7 @@
*
* \see [Page of the guide "WebSockets"](https://crowcpp.org/master/guides/websockets/).
*/
#define CROW_WEBSOCKET_ROUTE(app, url) app.route<crow::black_magic::get_parameter_tag(url)>(url).websocket<std::remove_reference<decltype(app)>::type>(&app)
#define CROW_WEBSOCKET_ROUTE(app, url) app.route<::http::black_magic::get_parameter_tag(url)>(url).websocket<std::remove_reference<decltype(app)>::type>(&app)
/**
* \def CROW_MIDDLEWARES(app, ...)
@ -174,7 +174,7 @@
/**
* \namespace crow
* \namespace http
* \brief The main namespace of the library. In this namespace
* is defined the most important classes and functions of the
* library.
@ -182,7 +182,7 @@
* Within this namespace, the Crow class, Router class, Connection
* class, and other are defined.
*/
namespace crow
namespace http
{
#ifdef CROW_ENABLE_SSL
using ssl_context_t = asio::ssl::context;
@ -375,7 +375,7 @@ namespace crow
/// - crow::LogLevel::Critical (4)
self_t& loglevel(LogLevel level)
{
crow::logger::setLogLevel(level);
logger::setLogLevel(level);
return *this;
}
@ -413,7 +413,7 @@ namespace crow
return *this;
}
std::function<void(crow::response&)>& exception_handler()
std::function<void(response&)>& exception_handler()
{
return router_.exception_handler();
}
@ -458,9 +458,9 @@ namespace crow
{
if (bp->static_dir().empty()) continue;
auto static_dir_ = crow::utility::normalize_path(bp->static_dir());
auto static_dir_ = utility::normalize_path(bp->static_dir());
bp->new_rule_tagged<crow::black_magic::get_parameter_tag(CROW_STATIC_ENDPOINT)>(CROW_STATIC_ENDPOINT)([static_dir_](crow::response& res, std::string file_path_partial) {
bp->new_rule_tagged<black_magic::get_parameter_tag(CROW_STATIC_ENDPOINT)>(CROW_STATIC_ENDPOINT)([static_dir_](response& res, std::string file_path_partial) {
utility::sanitize_filename(file_path_partial);
res.set_static_file_info_unsafe(static_dir_ + file_path_partial);
res.end();
@ -474,9 +474,9 @@ namespace crow
void add_static_dir()
{
if (are_static_routes_added()) return;
auto static_dir_ = crow::utility::normalize_path(CROW_STATIC_DIRECTORY);
auto static_dir_ = utility::normalize_path(CROW_STATIC_DIRECTORY);
route<crow::black_magic::get_parameter_tag(CROW_STATIC_ENDPOINT)>(CROW_STATIC_ENDPOINT)([static_dir_](crow::response& res, std::string file_path_partial) {
route<black_magic::get_parameter_tag(CROW_STATIC_ENDPOINT)>(CROW_STATIC_ENDPOINT)([static_dir_](response& res, std::string file_path_partial) {
utility::sanitize_filename(file_path_partial);
res.set_static_file_info_unsafe(static_dir_ + file_path_partial);
res.end();
@ -549,7 +549,7 @@ namespace crow
#endif
{
// TODO(EDev): Move these 6 lines to a method in http_server.
std::vector<crow::websocket::connection*> websockets_to_close = websockets_;
std::vector<websocket::connection*> websockets_to_close = websockets_;
for (auto websocket : websockets_to_close)
{
CROW_LOG_INFO << "Quitting Websocket: " << websocket;
@ -559,12 +559,12 @@ namespace crow
}
}
void add_websocket(crow::websocket::connection* conn)
void add_websocket(websocket::connection* conn)
{
websockets_.push_back(conn);
}
void remove_websocket(crow::websocket::connection* conn)
void remove_websocket(websocket::connection* conn)
{
websockets_.erase(std::remove(websockets_.begin(), websockets_.end(), conn), websockets_.end());
}
@ -762,7 +762,7 @@ namespace crow
bool server_started_{false};
std::condition_variable cv_started_;
std::mutex start_mutex_;
std::vector<crow::websocket::connection*> websockets_;
std::vector<websocket::connection*> websockets_;
};
/// \brief Alias of Crow<Middlewares...>. Useful if you want
@ -773,4 +773,4 @@ namespace crow
/// \brief Alias of Crow<>. Useful if you want a instance of
/// an Crow application that doesn't require of Middlewares
using SimpleApp = Crow<>;
} // namespace crow
} // namespace http

View File

@ -4,7 +4,7 @@
#include <unordered_map>
#include "http/utility.h"
namespace crow
namespace http
{
/// Hashing function for ci_map (unordered_multimap).
struct ci_hash
@ -38,4 +38,4 @@ namespace crow
};
using ci_map = std::unordered_multimap<std::string, std::string, ci_hash, ci_key_eq>;
} // namespace crow
} // namespace http

View File

@ -6,7 +6,7 @@
#include <iostream>
#include "http/utility.h"
namespace crow
namespace http
{
const char cr = '\r';
const char lf = '\n';
@ -297,57 +297,57 @@ namespace crow
r_params(r_params_),
method(method_) {}
};
} // namespace crow
} // namespace http
// clang-format off
#ifndef CROW_MSVC_WORKAROUND
constexpr crow::HTTPMethod method_from_string(const char* str)
constexpr http::HTTPMethod method_from_string(const char* str)
{
return crow::black_magic::is_equ_p(str, "GET", 3) ? crow::HTTPMethod::Get :
crow::black_magic::is_equ_p(str, "DELETE", 6) ? crow::HTTPMethod::Delete :
crow::black_magic::is_equ_p(str, "HEAD", 4) ? crow::HTTPMethod::Head :
crow::black_magic::is_equ_p(str, "POST", 4) ? crow::HTTPMethod::Post :
crow::black_magic::is_equ_p(str, "PUT", 3) ? crow::HTTPMethod::Put :
return http::black_magic::is_equ_p(str, "GET", 3) ? http::HTTPMethod::Get :
http::black_magic::is_equ_p(str, "DELETE", 6) ? http::HTTPMethod::Delete :
http::black_magic::is_equ_p(str, "HEAD", 4) ? http::HTTPMethod::Head :
http::black_magic::is_equ_p(str, "POST", 4) ? http::HTTPMethod::Post :
http::black_magic::is_equ_p(str, "PUT", 3) ? http::HTTPMethod::Put :
crow::black_magic::is_equ_p(str, "OPTIONS", 7) ? crow::HTTPMethod::Options :
crow::black_magic::is_equ_p(str, "CONNECT", 7) ? crow::HTTPMethod::Connect :
crow::black_magic::is_equ_p(str, "TRACE", 5) ? crow::HTTPMethod::Trace :
http::black_magic::is_equ_p(str, "OPTIONS", 7) ? http::HTTPMethod::Options :
http::black_magic::is_equ_p(str, "CONNECT", 7) ? http::HTTPMethod::Connect :
http::black_magic::is_equ_p(str, "TRACE", 5) ? http::HTTPMethod::Trace :
crow::black_magic::is_equ_p(str, "PATCH", 5) ? crow::HTTPMethod::Patch :
crow::black_magic::is_equ_p(str, "PURGE", 5) ? crow::HTTPMethod::Purge :
crow::black_magic::is_equ_p(str, "COPY", 4) ? crow::HTTPMethod::Copy :
crow::black_magic::is_equ_p(str, "LOCK", 4) ? crow::HTTPMethod::Lock :
crow::black_magic::is_equ_p(str, "MKCOL", 5) ? crow::HTTPMethod::MkCol :
crow::black_magic::is_equ_p(str, "MOVE", 4) ? crow::HTTPMethod::Move :
crow::black_magic::is_equ_p(str, "PROPFIND", 8) ? crow::HTTPMethod::Propfind :
crow::black_magic::is_equ_p(str, "PROPPATCH", 9) ? crow::HTTPMethod::Proppatch :
crow::black_magic::is_equ_p(str, "SEARCH", 6) ? crow::HTTPMethod::Search :
crow::black_magic::is_equ_p(str, "UNLOCK", 6) ? crow::HTTPMethod::Unlock :
crow::black_magic::is_equ_p(str, "BIND", 4) ? crow::HTTPMethod::Bind :
crow::black_magic::is_equ_p(str, "REBIND", 6) ? crow::HTTPMethod::Rebind :
crow::black_magic::is_equ_p(str, "UNBIND", 6) ? crow::HTTPMethod::Unbind :
crow::black_magic::is_equ_p(str, "ACL", 3) ? crow::HTTPMethod::Acl :
http::black_magic::is_equ_p(str, "PATCH", 5) ? http::HTTPMethod::Patch :
http::black_magic::is_equ_p(str, "PURGE", 5) ? http::HTTPMethod::Purge :
http::black_magic::is_equ_p(str, "COPY", 4) ? http::HTTPMethod::Copy :
http::black_magic::is_equ_p(str, "LOCK", 4) ? http::HTTPMethod::Lock :
http::black_magic::is_equ_p(str, "MKCOL", 5) ? http::HTTPMethod::MkCol :
http::black_magic::is_equ_p(str, "MOVE", 4) ? http::HTTPMethod::Move :
http::black_magic::is_equ_p(str, "PROPFIND", 8) ? http::HTTPMethod::Propfind :
http::black_magic::is_equ_p(str, "PROPPATCH", 9) ? http::HTTPMethod::Proppatch :
http::black_magic::is_equ_p(str, "SEARCH", 6) ? http::HTTPMethod::Search :
http::black_magic::is_equ_p(str, "UNLOCK", 6) ? http::HTTPMethod::Unlock :
http::black_magic::is_equ_p(str, "BIND", 4) ? http::HTTPMethod::Bind :
http::black_magic::is_equ_p(str, "REBIND", 6) ? http::HTTPMethod::Rebind :
http::black_magic::is_equ_p(str, "UNBIND", 6) ? http::HTTPMethod::Unbind :
http::black_magic::is_equ_p(str, "ACL", 3) ? http::HTTPMethod::Acl :
crow::black_magic::is_equ_p(str, "REPORT", 6) ? crow::HTTPMethod::Report :
crow::black_magic::is_equ_p(str, "MKACTIVITY", 10) ? crow::HTTPMethod::MkActivity :
crow::black_magic::is_equ_p(str, "CHECKOUT", 8) ? crow::HTTPMethod::Checkout :
crow::black_magic::is_equ_p(str, "MERGE", 5) ? crow::HTTPMethod::Merge :
http::black_magic::is_equ_p(str, "REPORT", 6) ? http::HTTPMethod::Report :
http::black_magic::is_equ_p(str, "MKACTIVITY", 10) ? http::HTTPMethod::MkActivity :
http::black_magic::is_equ_p(str, "CHECKOUT", 8) ? http::HTTPMethod::Checkout :
http::black_magic::is_equ_p(str, "MERGE", 5) ? http::HTTPMethod::Merge :
crow::black_magic::is_equ_p(str, "MSEARCH", 7) ? crow::HTTPMethod::MSearch :
crow::black_magic::is_equ_p(str, "NOTIFY", 6) ? crow::HTTPMethod::Notify :
crow::black_magic::is_equ_p(str, "SUBSCRIBE", 9) ? crow::HTTPMethod::Subscribe :
crow::black_magic::is_equ_p(str, "UNSUBSCRIBE", 11) ? crow::HTTPMethod::Unsubscribe :
http::black_magic::is_equ_p(str, "MSEARCH", 7) ? http::HTTPMethod::MSearch :
http::black_magic::is_equ_p(str, "NOTIFY", 6) ? http::HTTPMethod::Notify :
http::black_magic::is_equ_p(str, "SUBSCRIBE", 9) ? http::HTTPMethod::Subscribe :
http::black_magic::is_equ_p(str, "UNSUBSCRIBE", 11) ? http::HTTPMethod::Unsubscribe :
crow::black_magic::is_equ_p(str, "MKCALENDAR", 10) ? crow::HTTPMethod::MkCalendar :
http::black_magic::is_equ_p(str, "MKCALENDAR", 10) ? http::HTTPMethod::MkCalendar :
crow::black_magic::is_equ_p(str, "LINK", 4) ? crow::HTTPMethod::Link :
crow::black_magic::is_equ_p(str, "UNLINK", 6) ? crow::HTTPMethod::Unlink :
http::black_magic::is_equ_p(str, "LINK", 4) ? http::HTTPMethod::Link :
http::black_magic::is_equ_p(str, "UNLINK", 6) ? http::HTTPMethod::Unlink :
crow::black_magic::is_equ_p(str, "SOURCE", 6) ? crow::HTTPMethod::Source :
http::black_magic::is_equ_p(str, "SOURCE", 6) ? http::HTTPMethod::Source :
throw std::runtime_error("invalid http method");
}
constexpr crow::HTTPMethod operator"" _method(const char* str, size_t /*len*/)
constexpr http::HTTPMethod operator"" _method(const char* str, size_t /*len*/)
{
return method_from_string( str );
}

View File

@ -5,7 +5,7 @@
#include <zlib.h>
// http://zlib.net/manual.html
namespace crow // NOTE: Already documented in "crow/app.h"
namespace http // NOTE: Already documented in "crow/app.h"
{
namespace compression
{
@ -94,6 +94,6 @@ namespace crow // NOTE: Already documented in "crow/app.h"
return inflated_string;
}
} // namespace compression
} // namespace crow
} // namespace http
#endif

View File

@ -28,7 +28,7 @@
#include "http/task_timer.h"
#include "http/utility.h"
namespace crow
namespace http
{
#ifdef CROW_USE_BOOST
namespace asio = boost::asio;
@ -46,7 +46,7 @@ namespace crow
template<typename Adaptor, typename Handler, typename... Middlewares>
class Connection: public std::enable_shared_from_this<Connection<Adaptor, Handler, Middlewares...>>
{
friend struct crow::response;
friend struct response;
public:
Connection(
@ -633,4 +633,4 @@ namespace crow
std::atomic<unsigned int>& queue_length_;
};
} // namespace crow
} // namespace http

View File

@ -38,7 +38,7 @@ typedef unsigned __int64 uint64_t;
}
#include "http/common.h"
namespace crow
namespace http
{
/* Maximium header size allowed. If the macro is not defined
* before including this header then the default is used. To

View File

@ -13,7 +13,7 @@
#include "http/ci_map.h"
#include "http/query_string.h"
namespace crow // NOTE: Already documented in "crow/app.h"
namespace http // NOTE: Already documented in "crow/app.h"
{
#ifdef CROW_USE_BOOST
namespace asio = boost::asio;
@ -67,7 +67,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
const std::string& get_header_value(const std::string& key) const
{
return crow::get_header_value(headers, key);
return http::get_header_value(headers, key);
}
bool check_version(unsigned char major, unsigned char minor) const
@ -98,4 +98,4 @@ namespace crow // NOTE: Already documented in "crow/app.h"
io_service->dispatch(handler);
}
};
} // namespace crow
} // namespace http

View File

@ -22,7 +22,7 @@
#include "http/returnable.h"
namespace crow
namespace http
{
template<typename Adaptor, typename Handler, typename... Middlewares>
class Connection;
@ -33,7 +33,7 @@ namespace crow
struct response
{
template<typename Adaptor, typename Handler, typename... Middlewares>
friend class crow::Connection;
friend class Connection;
friend class Router;
@ -62,7 +62,7 @@ namespace crow
const std::string& get_header_value(const std::string& key)
{
return crow::get_header_value(headers, key);
return http::get_header_value(headers, key);
}
// naive validation of a mime-type string
@ -324,4 +324,4 @@ namespace crow
std::function<bool()> is_alive_helper_;
static_file_info file_info;
};
} // namespace crow
} // namespace http

View File

@ -28,7 +28,7 @@
#include "http/task_timer.h"
namespace crow // NOTE: Already documented in "crow/app.h"
namespace http // NOTE: Already documented in "crow/app.h"
{
#ifdef CROW_USE_BOOST
namespace asio = boost::asio;
@ -297,4 +297,4 @@ namespace crow // NOTE: Already documented in "crow/app.h"
typename Adaptor::context* adaptor_ctx_;
};
} // namespace crow
} // namespace http

View File

@ -25,7 +25,7 @@ using std::isinf;
using std::isnan;
namespace crow // NOTE: Already documented in "crow/app.h"
namespace http // NOTE: Already documented in "crow/app.h"
{
namespace mustache
{
@ -184,7 +184,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
e_ = s_ + length;
owned_ = 1;
}
friend rvalue crow::json::load(const char* data, size_t size);
friend rvalue json::load(const char* data, size_t size);
friend bool operator==(const r_string& l, const r_string& r);
friend bool operator==(const std::string& l, const r_string& r);
@ -1287,7 +1287,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
/// Write means this class is used to primarily assemble JSON objects using keys and values and export those into a string.
class wvalue : public returnable
{
friend class crow::mustache::template_t;
friend class mustache::template_t;
friend struct wvalue_reader;
public:
@ -1303,7 +1303,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
type t() const { return t_; }
/// Create an empty json value (outputs "{}" instead of a "null" string)
static crow::json::wvalue empty_object() { return crow::json::wvalue::object(); }
static json::wvalue empty_object() { return json::wvalue::object(); }
private:
type t_{type::Null}; ///< The type of the value.
@ -2080,4 +2080,4 @@ namespace crow // NOTE: Already documented in "crow/app.h"
//{
//}
} // namespace json
} // namespace crow
} // namespace http

View File

@ -9,7 +9,7 @@
#include <sstream>
#include <string>
namespace crow
namespace http
{
enum class LogLevel
{
@ -146,20 +146,20 @@ namespace crow
std::ostringstream stringstream_;
LogLevel level_;
};
} // namespace crow
} // namespace http
#define CROW_LOG_CRITICAL \
if (crow::logger::get_current_log_level() <= crow::LogLevel::Critical) \
crow::logger(crow::LogLevel::Critical)
if (http::logger::get_current_log_level() <= http::LogLevel::Critical) \
http::logger(http::LogLevel::Critical)
#define CROW_LOG_ERROR \
if (crow::logger::get_current_log_level() <= crow::LogLevel::Error) \
crow::logger(crow::LogLevel::Error)
if (http::logger::get_current_log_level() <= http::LogLevel::Error) \
http::logger(http::LogLevel::Error)
#define CROW_LOG_WARNING \
if (crow::logger::get_current_log_level() <= crow::LogLevel::Warning) \
crow::logger(crow::LogLevel::Warning)
if (http::logger::get_current_log_level() <= http::LogLevel::Warning) \
http::logger(http::LogLevel::Warning)
#define CROW_LOG_INFO \
if (crow::logger::get_current_log_level() <= crow::LogLevel::Info) \
crow::logger(crow::LogLevel::Info)
if (http::logger::get_current_log_level() <= http::LogLevel::Info) \
http::logger(http::LogLevel::Info)
#define CROW_LOG_DEBUG \
if (crow::logger::get_current_log_level() <= crow::LogLevel::Debug) \
crow::logger(crow::LogLevel::Debug)
if (http::logger::get_current_log_level() <= http::LogLevel::Debug) \
http::logger(http::LogLevel::Debug)

View File

@ -9,7 +9,7 @@
#include <iostream>
#include <utility>
namespace crow // NOTE: Already documented in "crow/app.h"
namespace http // NOTE: Already documented in "crow/app.h"
{
/// Local middleware should extend ILocalMiddleware
@ -211,38 +211,38 @@ namespace crow // NOTE: Already documented in "crow/app.h"
template<typename F, typename... Args>
typename std::enable_if<black_magic::CallHelper<F, black_magic::S<Args...>>::value, void>::type
wrapped_handler_call(crow::request& /*req*/, crow::response& res, const F& f, Args&&... args)
wrapped_handler_call(request& /*req*/, response& res, const F& f, Args&&... args)
{
static_assert(!std::is_same<void, decltype(f(std::declval<Args>()...))>::value,
"Handler function cannot have void return type; valid return types: string, int, crow::response, crow::returnable");
res = crow::response(f(std::forward<Args>(args)...));
res = response(f(std::forward<Args>(args)...));
res.end();
}
template<typename F, typename... Args>
typename std::enable_if<
!black_magic::CallHelper<F, black_magic::S<Args...>>::value &&
black_magic::CallHelper<F, black_magic::S<crow::request&, Args...>>::value,
black_magic::CallHelper<F, black_magic::S<request&, Args...>>::value,
void>::type
wrapped_handler_call(crow::request& req, crow::response& res, const F& f, Args&&... args)
wrapped_handler_call(request& req, response& res, const F& f, Args&&... args)
{
static_assert(!std::is_same<void, decltype(f(std::declval<crow::request>(), std::declval<Args>()...))>::value,
static_assert(!std::is_same<void, decltype(f(std::declval<request>(), std::declval<Args>()...))>::value,
"Handler function cannot have void return type; valid return types: string, int, crow::response, crow::returnable");
res = crow::response(f(req, std::forward<Args>(args)...));
res = response(f(req, std::forward<Args>(args)...));
res.end();
}
template<typename F, typename... Args>
typename std::enable_if<
!black_magic::CallHelper<F, black_magic::S<Args...>>::value &&
!black_magic::CallHelper<F, black_magic::S<crow::request&, Args...>>::value &&
black_magic::CallHelper<F, black_magic::S<crow::response&, Args...>>::value,
!black_magic::CallHelper<F, black_magic::S<request&, Args...>>::value &&
black_magic::CallHelper<F, black_magic::S<response&, Args...>>::value,
void>::type
wrapped_handler_call(crow::request& /*req*/, crow::response& res, const F& f, Args&&... args)
wrapped_handler_call(request& /*req*/, response& res, const F& f, Args&&... args)
{
static_assert(std::is_same<void, decltype(f(std::declval<crow::response&>(), std::declval<Args>()...))>::value,
static_assert(std::is_same<void, decltype(f(std::declval<response&>(), std::declval<Args>()...))>::value,
"Handler function with response argument should have void return type");
f(res, std::forward<Args>(args)...);
@ -251,13 +251,13 @@ namespace crow // NOTE: Already documented in "crow/app.h"
template<typename F, typename... Args>
typename std::enable_if<
!black_magic::CallHelper<F, black_magic::S<Args...>>::value &&
!black_magic::CallHelper<F, black_magic::S<crow::request&, Args...>>::value &&
!black_magic::CallHelper<F, black_magic::S<crow::response&, Args...>>::value &&
black_magic::CallHelper<F, black_magic::S<const crow::request&, crow::response&, Args...>>::value,
!black_magic::CallHelper<F, black_magic::S<request&, Args...>>::value &&
!black_magic::CallHelper<F, black_magic::S<response&, Args...>>::value &&
black_magic::CallHelper<F, black_magic::S<const request&, response&, Args...>>::value,
void>::type
wrapped_handler_call(crow::request& req, crow::response& res, const F& f, Args&&... args)
wrapped_handler_call(request& req, response& res, const F& f, Args&&... args)
{
static_assert(std::is_same<void, decltype(f(std::declval<crow::request&>(), std::declval<crow::response&>(), std::declval<Args>()...))>::value,
static_assert(std::is_same<void, decltype(f(std::declval<request&>(), std::declval<response&>(), std::declval<Args>()...))>::value,
"Handler function with response argument should have void return type");
f(req, res, std::forward<Args>(args)...);
@ -267,13 +267,13 @@ namespace crow // NOTE: Already documented in "crow/app.h"
template<typename F, typename... Args>
typename std::enable_if<
!black_magic::CallHelper<F, black_magic::S<Args...>>::value &&
!black_magic::CallHelper<F, black_magic::S<crow::request&, Args...>>::value &&
!black_magic::CallHelper<F, black_magic::S<crow::response&, Args...>>::value &&
!black_magic::CallHelper<F, black_magic::S<const crow::request&, crow::response&, Args...>>::value,
!black_magic::CallHelper<F, black_magic::S<request&, Args...>>::value &&
!black_magic::CallHelper<F, black_magic::S<response&, Args...>>::value &&
!black_magic::CallHelper<F, black_magic::S<const request&, response&, Args...>>::value,
void>::type
wrapped_handler_call(crow::request& req, crow::response& res, const F& f, Args&&... args)
wrapped_handler_call(request& req, response& res, const F& f, Args&&... args)
{
static_assert(std::is_same<void, decltype(f(std::declval<crow::request&>(), std::declval<crow::response&>(), std::declval<Args>()...))>::value,
static_assert(std::is_same<void, decltype(f(std::declval<request&>(), std::declval<response&>(), std::declval<Args>()...))>::value,
"Handler function with response argument should have void return type");
f(req, res, std::forward<Args>(args)...);
@ -328,4 +328,4 @@ namespace crow // NOTE: Already documented in "crow/app.h"
};
} // namespace detail
} // namespace crow
} // namespace http

View File

@ -4,7 +4,7 @@
#include "http/http_request.h"
#include "http/http_response.h"
namespace crow
namespace http
{
namespace detail
{
@ -13,7 +13,7 @@ namespace crow
template<typename... Middlewares>
struct partial_context : public black_magic::pop_back<Middlewares...>::template rebind<partial_context>, public black_magic::last_element_type<Middlewares...>::type::context
{
using parent_context = typename black_magic::pop_back<Middlewares...>::template rebind<::crow::detail::partial_context>;
using parent_context = typename black_magic::pop_back<Middlewares...>::template rebind<detail::partial_context>;
template<int N>
using partial = typename std::conditional<N == sizeof...(Middlewares) - 1, partial_context, typename parent_context::template partial<N>>::type;
@ -57,4 +57,4 @@ namespace crow
using partial = typename partial_context<Middlewares...>::template partial<N>;
};
} // namespace detail
} // namespace crow
} // namespace http

View File

@ -5,7 +5,7 @@
#include "http/http_request.h"
#include "http/http_response.h"
namespace crow
namespace http
{
// Any middleware requires following 3 members:
@ -304,4 +304,4 @@ namespace crow
SimpleApp
*/
} // namespace crow
} // namespace http

View File

@ -3,14 +3,14 @@
#include "http/http_response.h"
#include "http/routing.h"
namespace crow
namespace http
{
struct CORSHandler;
/// Used for tuning CORS policies
struct CORSRules
{
friend struct crow::CORSHandler;
friend struct CORSHandler;
/// Set Access-Control-Allow-Origin. Default is "*"
CORSRules& origin(const std::string& origin)
@ -20,17 +20,17 @@ namespace crow
}
/// Set Access-Control-Allow-Methods. Default is "*"
CORSRules& methods(crow::HTTPMethod method)
CORSRules& methods(HTTPMethod method)
{
add_list_item(methods_, crow::method_name(method));
add_list_item(methods_, method_name(method));
return *this;
}
/// Set Access-Control-Allow-Methods. Default is "*"
template<typename... Methods>
CORSRules& methods(crow::HTTPMethod method, Methods... method_list)
CORSRules& methods(HTTPMethod method, Methods... method_list)
{
add_list_item(methods_, crow::method_name(method));
add_list_item(methods_, method_name(method));
methods(method_list...);
return *this;
}
@ -94,7 +94,7 @@ namespace crow
}
/// Set header `key` to `value` if it is not set
void set_header_no_override(const std::string& key, const std::string& value, crow::response& res)
void set_header_no_override(const std::string& key, const std::string& value, response& res)
{
if (value.size() == 0) return;
if (!get_header_value(res.headers, key).empty()) return;
@ -102,7 +102,7 @@ namespace crow
}
/// Set response headers
void apply(crow::response& res)
void apply(response& res)
{
if (ignore_) return;
set_header_no_override("Access-Control-Allow-Origin", origin_, res);
@ -134,10 +134,10 @@ namespace crow
struct context
{};
void before_handle(crow::request& /*req*/, crow::response& /*res*/, context& /*ctx*/)
void before_handle(request& /*req*/, response& /*res*/, context& /*ctx*/)
{}
void after_handle(crow::request& req, crow::response& res, context& /*ctx*/)
void after_handle(request& req, response& res, context& /*ctx*/)
{
auto& rule = find_rule(req.url);
rule.apply(res);
@ -197,4 +197,4 @@ namespace crow
return handler_->global();
}
} // namespace crow
} // namespace http

View File

@ -48,7 +48,7 @@ namespace
using wrap_mv_t = wrap_char_t<wrap_integral_t<T>>;
} // namespace
namespace crow
namespace http
{
namespace session
{
@ -601,4 +601,4 @@ namespace crow
session::ExpirationTracker expirations_;
};
} // namespace crow
} // namespace http

View File

@ -2,7 +2,7 @@
#include "http/http_request.h"
#include "http/http_response.h"
namespace crow
namespace http
{
struct UTF8
@ -22,4 +22,4 @@ namespace crow
}
};
} // namespace crow
} // namespace http

View File

@ -2,7 +2,7 @@
#include <unordered_map>
#include <string>
namespace crow
namespace http
{
const std::unordered_map<std::string, std::string> mime_types{
{"shtml", "text/html"},

View File

@ -8,7 +8,7 @@
#include "http/returnable.h"
#include "http/ci_map.h"
namespace crow
namespace http
{
/// Encapsulates anything related to processing and organizing `multipart/xyz` messages
@ -80,7 +80,7 @@ namespace crow
const std::string& get_header_value(const std::string& key) const
{
return crow::get_header_value(headers, key);
return http::get_header_value(headers, key);
}
part get_part_by_name(const std::string& name)
@ -270,4 +270,4 @@ namespace crow
}
};
} // namespace multipart
} // namespace crow
} // namespace http

View File

@ -9,7 +9,7 @@
#include "http/returnable.h"
#include "http/utility.h"
namespace crow
namespace http
{
namespace mustache
{
@ -718,4 +718,4 @@ namespace crow
return compile(detail::get_loader_ref()(filename));
}
} // namespace mustache
} // namespace crow
} // namespace http

View File

@ -7,7 +7,7 @@
#include "http/http_request.h"
#include "http/http_parser_merged.h"
namespace crow
namespace http
{
/// A wrapper for `nodejs/http-parser`.
@ -138,7 +138,7 @@ namespace crow
void clear()
{
req = crow::request();
req = request();
header_field.clear();
header_value.clear();
header_building_state = 0;
@ -194,7 +194,7 @@ namespace crow
Handler* handler_; ///< This is currently an HTTP connection object (\ref crow.Connection).
};
} // namespace crow
} // namespace http
#undef CROW_NEW_MESSAGE
#undef CROW_start_state

View File

@ -8,7 +8,7 @@
#include <iostream>
#include <memory>
namespace crow
namespace http
{
// ----------------------------------------------------------------------------
@ -286,7 +286,7 @@ inline char * qs_scanvalue(const char * key, const char * qs, char * val, size_t
// ----------------------------------------------------------------------------
namespace crow
namespace http
{
struct request;
/// A class to represent any data coming after the `?` in the request URL into key-value pairs.
@ -486,4 +486,4 @@ namespace crow
std::vector<char*> key_value_pairs_;
};
} // namespace crow
} // namespace http

View File

@ -2,7 +2,7 @@
#include <string>
namespace crow
namespace http
{
/// An abstract class that allows any other class to be returned by a handler.
struct returnable
@ -16,4 +16,4 @@ namespace crow
virtual ~returnable(){};
};
} // namespace crow
} // namespace http

View File

@ -18,7 +18,7 @@
#include "http/mustache.h"
#include "http/middleware.h"
namespace crow // NOTE: Already documented in "crow/app.h"
namespace http // NOTE: Already documented in "crow/app.h"
{
constexpr const uint16_t INVALID_BP_ID{((uint16_t)-1)};
@ -37,7 +37,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
{
using MwContainer = typename App::mw_container_t;
static_assert(black_magic::has_type<MW, MwContainer>::value, "Middleware must be present in app");
static_assert(std::is_base_of<crow::ILocalMiddleware, MW>::value, "Middleware must extend ILocalMiddleware");
static_assert(std::is_base_of<ILocalMiddleware, MW>::value, "Middleware must extend ILocalMiddleware");
int idx = black_magic::tuple_index<MW, MwContainer>::value;
indices_.push_back(idx);
push<App, Middlewares...>();
@ -301,21 +301,21 @@ namespace crow // NOTE: Already documented in "crow/app.h"
template<typename... Args>
struct handler_type_helper
{
using type = std::function<void(const crow::request&, crow::response&, Args...)>;
using type = std::function<void(const request&, response&, Args...)>;
using args_type = black_magic::S<typename black_magic::promote_t<Args>...>;
};
template<typename... Args>
struct handler_type_helper<const request&, Args...>
{
using type = std::function<void(const crow::request&, crow::response&, Args...)>;
using type = std::function<void(const request&, response&, Args...)>;
using args_type = black_magic::S<typename black_magic::promote_t<Args>...>;
};
template<typename... Args>
struct handler_type_helper<const request&, response&, Args...>
{
using type = std::function<void(const crow::request&, crow::response&, Args...)>;
using type = std::function<void(const request&, response&, Args...)>;
using args_type = black_magic::S<typename black_magic::promote_t<Args>...>;
};
@ -366,11 +366,11 @@ namespace crow // NOTE: Already documented in "crow/app.h"
template<typename Func>
typename std::enable_if<
!black_magic::CallHelper<Func, black_magic::S<>>::value &&
black_magic::CallHelper<Func, black_magic::S<crow::request>>::value,
black_magic::CallHelper<Func, black_magic::S<request>>::value,
void>::type
operator()(Func&& f)
{
static_assert(!std::is_same<void, decltype(f(std::declval<crow::request>()))>::value,
static_assert(!std::is_same<void, decltype(f(std::declval<request>()))>::value,
"Handler function cannot have void return type; valid return types: string, int, crow::response, crow::returnable");
handler_ = (
@ -379,7 +379,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
#else
[f]
#endif
(const crow::request& req, crow::response& res) {
(const request& req, response& res) {
res = response(f(req));
res.end();
});
@ -388,12 +388,12 @@ namespace crow // NOTE: Already documented in "crow/app.h"
template<typename Func>
typename std::enable_if<
!black_magic::CallHelper<Func, black_magic::S<>>::value &&
!black_magic::CallHelper<Func, black_magic::S<crow::request>>::value &&
black_magic::CallHelper<Func, black_magic::S<crow::response&>>::value,
!black_magic::CallHelper<Func, black_magic::S<request>>::value &&
black_magic::CallHelper<Func, black_magic::S<response&>>::value,
void>::type
operator()(Func&& f)
{
static_assert(std::is_same<void, decltype(f(std::declval<crow::response&>()))>::value,
static_assert(std::is_same<void, decltype(f(std::declval<response&>()))>::value,
"Handler function with response argument should have void return type");
handler_ = (
#ifdef CROW_CAN_USE_CPP14
@ -401,7 +401,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
#else
[f]
#endif
(const crow::request&, crow::response& res) {
(const request&, response& res) {
f(res);
});
}
@ -409,12 +409,12 @@ namespace crow // NOTE: Already documented in "crow/app.h"
template<typename Func>
typename std::enable_if<
!black_magic::CallHelper<Func, black_magic::S<>>::value &&
!black_magic::CallHelper<Func, black_magic::S<crow::request>>::value &&
!black_magic::CallHelper<Func, black_magic::S<crow::response&>>::value,
!black_magic::CallHelper<Func, black_magic::S<request>>::value &&
!black_magic::CallHelper<Func, black_magic::S<response&>>::value,
void>::type
operator()(Func&& f)
{
static_assert(std::is_same<void, decltype(f(std::declval<crow::request>(), std::declval<crow::response&>()))>::value,
static_assert(std::is_same<void, decltype(f(std::declval<request>(), std::declval<response&>()))>::value,
"Handler function with response argument should have void return type");
handler_ = std::move(f);
@ -429,7 +429,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
friend class Router;
private:
std::function<void(const crow::request&, crow::response&)> handler_;
std::function<void(const request&, response&)> handler_;
};
@ -461,7 +461,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
void handle_upgrade(const request& req, response&, SocketAdaptor&& adaptor) override
{
max_payload_ = max_payload_override_ ? max_payload_ : app_->websocket_max_payload();
new crow::websocket::Connection<SocketAdaptor, App>(req, std::move(adaptor), app_, max_payload_, open_handler_, message_handler_, close_handler_, error_handler_, accept_handler_);
new websocket::Connection<SocketAdaptor, App>(req, std::move(adaptor), app_, max_payload_, open_handler_, message_handler_, close_handler_, error_handler_, accept_handler_);
}
#ifdef CROW_ENABLE_SSL
void handle_upgrade(const request& req, response&, SSLAdaptor&& adaptor) override
@ -515,11 +515,11 @@ namespace crow // NOTE: Already documented in "crow/app.h"
protected:
App* app_;
std::function<void(crow::websocket::connection&)> open_handler_;
std::function<void(crow::websocket::connection&, const std::string&, bool)> message_handler_;
std::function<void(crow::websocket::connection&, const std::string&)> close_handler_;
std::function<void(crow::websocket::connection&, const std::string&)> error_handler_;
std::function<bool(const crow::request&, void**)> accept_handler_;
std::function<void(websocket::connection&)> open_handler_;
std::function<void(websocket::connection&, const std::string&, bool)> message_handler_;
std::function<void(websocket::connection&, const std::string&)> close_handler_;
std::function<void(websocket::connection&, const std::string&)> error_handler_;
std::function<bool(const request&, void**)> accept_handler_;
uint64_t max_payload_;
bool max_payload_override_ = false;
};
@ -677,7 +677,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
#else
[f]
#endif
(crow::request& req, crow::response& res, Args... args) {
(request& req, response& res, Args... args) {
detail::wrapped_handler_call(req, res, f, std::forward<Args>(args)...);
});
}
@ -705,7 +705,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
}
private:
std::function<void(crow::request&, crow::response&, Args...)> handler_;
std::function<void(request&, response&, Args...)> handler_;
};
const int RULE_SPECIAL_REDIRECT_SLASH = 1;
@ -1724,7 +1724,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
template<typename App>
typename std::enable_if<std::tuple_size<typename App::mw_container_t>::value != 0, void>::type
handle_rule(BaseRule* rule, crow::request& req, crow::response& res, const crow::routing_params& rp)
handle_rule(BaseRule* rule, request& req, response& res, const routing_params& rp)
{
if (!rule->mw_indices_.empty())
{
@ -1760,7 +1760,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
template<typename App>
typename std::enable_if<std::tuple_size<typename App::mw_container_t>::value == 0, void>::type
handle_rule(BaseRule* rule, crow::request& req, crow::response& res, const crow::routing_params& rp)
handle_rule(BaseRule* rule, request& req, response& res, const routing_params& rp)
{
rule->handle(req, res, rp);
}
@ -1783,7 +1783,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
return blueprints_;
}
std::function<void(crow::response&)>& exception_handler()
std::function<void(response&)>& exception_handler()
{
return exception_handler_;
}
@ -1822,6 +1822,6 @@ namespace crow // NOTE: Already documented in "crow/app.h"
std::array<PerMethod, static_cast<int>(HTTPMethod::InternalMethodCount)> per_methods_;
std::vector<std::unique_ptr<BaseRule>> all_rules_;
std::vector<Blueprint*> blueprints_;
std::function<void(crow::response&)> exception_handler_ = &default_exception_handler;
std::function<void(response&)> exception_handler_ = &default_exception_handler;
};
} // namespace crow
} // namespace http

View File

@ -24,7 +24,7 @@
#define GET_IO_SERVICE(s) ((s).get_io_service())
#endif
namespace crow
namespace http
{
#ifdef CROW_USE_BOOST
namespace asio = boost::asio;
@ -185,4 +185,4 @@ namespace crow
std::unique_ptr<asio::ssl::stream<tcp::socket>> ssl_socket_;
};
#endif
} // namespace crow
} // namespace http

View File

@ -18,7 +18,7 @@
#include "http/logging.h"
namespace crow
namespace http
{
#ifdef CROW_USE_BOOST
namespace asio = boost::asio;
@ -145,4 +145,4 @@ namespace crow
identifier_type highest_id_{0};
};
} // namespace detail
} // namespace crow
} // namespace http

View File

@ -28,7 +28,7 @@
#define CROW_UNLIKELY(X) (X)
#endif
namespace crow
namespace http
{
/// @cond SKIP
namespace black_magic
@ -907,4 +907,4 @@ namespace crow
return v.substr(begin, end - begin);
}
} // namespace utility
} // namespace crow
} // namespace http

View File

@ -1,6 +1,6 @@
#pragma once
namespace crow
namespace http
{
constexpr const char VERSION[] = "master";
}

View File

@ -6,7 +6,7 @@
#include "http/TinySHA1.hpp"
#include "http/utility.h"
namespace crow // NOTE: Already documented in "crow/app.h"
namespace http // NOTE: Already documented in "crow/app.h"
{
#ifdef CROW_USE_BOOST
namespace asio = boost::asio;
@ -16,7 +16,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
#endif
/**
* \namespace crow::websocket
* \namespace http::websocket
* \brief Namespace that includes the \ref Connection class
* and \ref connection struct. Useful for WebSockets connection.
*
@ -85,12 +85,12 @@ namespace crow // NOTE: Already documented in "crow/app.h"
///
/// Requires a request with an "Upgrade: websocket" header.<br>
/// Automatically handles the handshake.
Connection(const crow::request& req, Adaptor&& adaptor, Handler* handler, uint64_t max_payload,
std::function<void(crow::websocket::connection&)> open_handler,
std::function<void(crow::websocket::connection&, const std::string&, bool)> message_handler,
std::function<void(crow::websocket::connection&, const std::string&)> close_handler,
std::function<void(crow::websocket::connection&, const std::string&)> error_handler,
std::function<bool(const crow::request&, void**)> accept_handler):
Connection(const request& req, Adaptor&& adaptor, Handler* handler, uint64_t max_payload,
std::function<void(websocket::connection&)> open_handler,
std::function<void(websocket::connection&, const std::string&, bool)> message_handler,
std::function<void(websocket::connection&, const std::string&)> close_handler,
std::function<void(websocket::connection&, const std::string&)> error_handler,
std::function<bool(const request&, void**)> accept_handler):
adaptor_(std::move(adaptor)),
handler_(handler),
max_payload_bytes_(max_payload),
@ -129,7 +129,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
uint8_t digest[20];
s.getDigestBytes(digest);
start(crow::utility::base64encode((unsigned char*)digest, 20));
start(utility::base64encode((unsigned char*)digest, 20));
}
~Connection() noexcept override
@ -748,11 +748,11 @@ namespace crow // NOTE: Already documented in "crow/app.h"
std::shared_ptr<void> anchor_ = std::make_shared<int>(); // Value is just for placeholding
std::function<void(crow::websocket::connection&)> open_handler_;
std::function<void(crow::websocket::connection&, const std::string&, bool)> message_handler_;
std::function<void(crow::websocket::connection&, const std::string&)> close_handler_;
std::function<void(crow::websocket::connection&, const std::string&)> error_handler_;
std::function<bool(const crow::request&, void**)> accept_handler_;
std::function<void(websocket::connection&)> open_handler_;
std::function<void(websocket::connection&, const std::string&, bool)> message_handler_;
std::function<void(websocket::connection&, const std::string&)> close_handler_;
std::function<void(websocket::connection&, const std::string&)> error_handler_;
std::function<bool(const request&, void**)> accept_handler_;
};
} // namespace websocket
} // namespace crow
} // namespace http

View File

@ -27,7 +27,7 @@ def main():
"#include <unordered_map>",
"#include <string>",
"",
"namespace crow",
"namespace http",
"{",
tabspace + "const std::unordered_map<std::string, std::string> mime_types{"])

View File

@ -7,8 +7,8 @@
#include "crow/mustache.h"
using namespace std;
using namespace crow;
using namespace crow::mustache;
using namespace http;
using namespace http::mustache;
string read_all(const string& filename)
{

View File

@ -40,7 +40,7 @@
#include "http/middlewares/session.h"
using namespace std;
using namespace crow;
using namespace http;
#ifdef CROW_USE_BOOST
namespace asio = boost::asio;
@ -85,7 +85,7 @@ TEST_CASE("Rule")
CHECK(1 == x);
// registering handler with request argument
r([&x](const crow::request&) {
r([&x](const request&) {
x = 2;
return "";
});
@ -372,7 +372,7 @@ TEST_CASE("handler_with_response")
{
SimpleApp app;
CROW_ROUTE(app, "/")
([](const crow::request&, crow::response&) {});
([](const request&, response&) {});
} // handler_with_response
TEST_CASE("http_method")
@ -1376,8 +1376,8 @@ TEST_CASE("json_list")
TEST_CASE("template_basic")
{
auto t = crow::mustache::compile(R"---(attack of {{name}})---");
crow::mustache::context ctx;
auto t = mustache::compile(R"---(attack of {{name}})---");
mustache::context ctx;
ctx["name"] = "killer tomatoes";
auto result = t.render_string(ctx);
CHECK("attack of killer tomatoes" == result);
@ -1385,8 +1385,8 @@ TEST_CASE("template_basic")
TEST_CASE("template_true_tag")
{
auto t = crow::mustache::compile(R"---({{true_value}})---");
crow::mustache::context ctx;
auto t = mustache::compile(R"---({{true_value}})---");
mustache::context ctx;
ctx["true_value"] = true;
auto result = t.render_string(ctx);
CHECK("true" == result);
@ -1394,8 +1394,8 @@ TEST_CASE("template_true_tag")
TEST_CASE("template_false_tag")
{
auto t = crow::mustache::compile(R"---({{false_value}})---");
crow::mustache::context ctx;
auto t = mustache::compile(R"---({{false_value}})---");
mustache::context ctx;
ctx["false_value"] = false;
auto result = t.render_string(ctx);
CHECK("false" == result);
@ -1403,8 +1403,8 @@ TEST_CASE("template_false_tag")
TEST_CASE("template_function")
{
auto t = crow::mustache::compile("attack of {{func}}");
crow::mustache::context ctx;
auto t = mustache::compile("attack of {{func}}");
mustache::context ctx;
ctx["name"] = "killer tomatoes";
ctx["func"] = std::function<std::string(std::string)>([&](std::string) {
return std::string("{{name}}, IN SPACE!");
@ -1415,10 +1415,10 @@ TEST_CASE("template_function")
TEST_CASE("template_load")
{
crow::mustache::set_base(".");
mustache::set_base(".");
ofstream("test.mustache") << R"---(attack of {{name}})---";
auto t = crow::mustache::load("test.mustache");
crow::mustache::context ctx;
auto t = mustache::load("test.mustache");
mustache::context ctx;
ctx["name"] = "killer tomatoes";
auto result = t.render_string(ctx);
CHECK("attack of killer tomatoes" == result);
@ -1431,10 +1431,10 @@ TEST_CASE("TemplateRouting")
CROW_ROUTE(app, "/temp")
([] {
auto t = crow::mustache::compile(R"---(attack of {{name}})---");
crow::mustache::context ctx;
auto t = mustache::compile(R"---(attack of {{name}})---");
mustache::context ctx;
ctx["name"] = "killer tomatoes";
return crow::response(t.render(ctx));
return response(t.render(ctx));
});
app.validate();
@ -1448,7 +1448,7 @@ TEST_CASE("TemplateRouting")
app.handle_full(req, res);
CHECK("attack of killer tomatoes" == res.body);
CHECK("text/html" == crow::get_header_value(res.headers, "Content-Type"));
CHECK("text/html" == get_header_value(res.headers, "Content-Type"));
}
} // PathRouting
@ -1496,7 +1496,7 @@ TEST_CASE("middleware_simple")
App<NullMiddleware, NullSimpleMiddleware> app;
decltype(app)::server_t server(&app, LOCALHOST_ADDRESS, 45451);
CROW_ROUTE(app, "/")
([&](const crow::request& req) {
([&](const request& req) {
app.get_context<NullMiddleware>(req);
app.get_context<NullSimpleMiddleware>(req);
return "";
@ -1529,7 +1529,7 @@ struct empty_type
{};
template<bool Local>
struct FirstMW : public std::conditional<Local, crow::ILocalMiddleware, empty_type>::type
struct FirstMW : public std::conditional<Local, ILocalMiddleware, empty_type>::type
{
struct context
{
@ -1549,7 +1549,7 @@ struct FirstMW : public std::conditional<Local, crow::ILocalMiddleware, empty_ty
};
template<bool Local>
struct SecondMW : public std::conditional<Local, crow::ILocalMiddleware, empty_type>::type
struct SecondMW : public std::conditional<Local, ILocalMiddleware, empty_type>::type
{
struct context
{};
@ -1568,7 +1568,7 @@ struct SecondMW : public std::conditional<Local, crow::ILocalMiddleware, empty_t
};
template<bool Local>
struct ThirdMW : public std::conditional<Local, crow::ILocalMiddleware, empty_type>::type
struct ThirdMW : public std::conditional<Local, ILocalMiddleware, empty_type>::type
{
struct context
{};
@ -1676,7 +1676,7 @@ TEST_CASE("middleware_context")
app.stop();
} // middleware_context
struct LocalSecretMiddleware : crow::ILocalMiddleware
struct LocalSecretMiddleware : ILocalMiddleware
{
struct context
{};
@ -1769,7 +1769,7 @@ TEST_CASE("middleware_blueprint")
Blueprint bp3("c", "c3", "c3");
CROW_BP_ROUTE(bp2, "/")
.CROW_MIDDLEWARES(app, ThirdMW<true>)([&app](const crow::request& req) {
.CROW_MIDDLEWARES(app, ThirdMW<true>)([&app](const request& req) {
{
auto& ctx = app.get_context<FirstMW<true>>(req);
ctx.v.push_back("handle");
@ -1778,7 +1778,7 @@ TEST_CASE("middleware_blueprint")
});
CROW_BP_ROUTE(bp3, "/break")
.CROW_MIDDLEWARES(app, SecondMW<true>, ThirdMW<true>)([&app](const crow::request& req) {
.CROW_MIDDLEWARES(app, SecondMW<true>, ThirdMW<true>)([&app](const request& req) {
{
auto& ctx = app.get_context<FirstMW<true>>(req);
ctx.v.push_back("handle");
@ -1961,9 +1961,9 @@ TEST_CASE("middleware_cors")
{
static char buf[5012];
App<crow::CORSHandler> app;
App<CORSHandler> app;
auto& cors = app.get_middleware<crow::CORSHandler>();
auto& cors = app.get_middleware<CORSHandler>();
// clang-format off
cors
.prefix("/origin")
@ -2054,7 +2054,7 @@ TEST_CASE("middleware_session")
using Session = SessionMiddleware<InMemoryStore>;
App<crow::CookieParser, Session> app{
App<CookieParser, Session> app{
Session{InMemoryStore{}}};
CROW_ROUTE(app, "/get")
@ -2214,7 +2214,7 @@ TEST_CASE("simple_url_params")
query_string last_url_params;
CROW_ROUTE(app, "/params")
([&last_url_params](const crow::request& req) {
([&last_url_params](const request& req) {
last_url_params = std::move(req.url_params);
return "OK";
});
@ -2467,7 +2467,7 @@ TEST_CASE("multipart")
SimpleApp app;
CROW_ROUTE(app, "/multipart")
([](const crow::request& req, crow::response& res) {
([](const request& req, response& res) {
multipart::message msg(req);
res.body = msg.dump();
res.end();
@ -2519,20 +2519,20 @@ TEST_CASE("send_file")
SimpleApp app;
CROW_ROUTE(app, "/jpg")
([](const crow::request&, crow::response& res) {
([](const request&, response& res) {
res.set_static_file_info("tests/img/cat.jpg");
res.end();
});
CROW_ROUTE(app, "/jpg2")
([](const crow::request&, crow::response& res) {
([](const request&, response& res) {
res.set_static_file_info(
"tests/img/cat2.jpg"); // This file is nonexistent on purpose
res.end();
});
CROW_ROUTE(app, "/filewith.badext")
([](const crow::request&, crow::response& res) {
([](const request&, response& res) {
res.set_static_file_info("tests/img/filewith.badext");
res.end();
});
@ -2608,7 +2608,7 @@ TEST_CASE("stream_response")
key_response += keyword_;
CROW_ROUTE(app, "/test")
([&key_response](const crow::request&, crow::response& res) {
([&key_response](const request&, response& res) {
res.body = key_response;
res.end();
});
@ -2679,7 +2679,7 @@ TEST_CASE("websocket")
SimpleApp app;
CROW_WEBSOCKET_ROUTE(app, "/ws")
.onaccept([&](const crow::request& req, void**) {
.onaccept([&](const request& req, void**) {
CROW_LOG_INFO << "Accepted websocket with URL " << req.url;
return true;
})
@ -2842,7 +2842,7 @@ TEST_CASE("websocket_missing_host")
SimpleApp app;
CROW_WEBSOCKET_ROUTE(app, "/ws")
.onaccept([&](const crow::request& req, void**) {
.onaccept([&](const request& req, void**) {
CROW_LOG_INFO << "Accepted websocket with URL " << req.url;
return true;
})
@ -3243,10 +3243,10 @@ TEST_CASE("catchall")
TEST_CASE("blueprint")
{
SimpleApp app;
crow::Blueprint bp("bp_prefix", "cstat", "ctemplate");
crow::Blueprint bp_not_sub("bp_prefix_second");
crow::Blueprint sub_bp("bp2", "csstat", "cstemplate");
crow::Blueprint sub_sub_bp("bp3");
Blueprint bp("bp_prefix", "cstat", "ctemplate");
Blueprint bp_not_sub("bp_prefix_second");
Blueprint sub_bp("bp2", "csstat", "cstemplate");
Blueprint sub_sub_bp("bp3");
CROW_BP_ROUTE(sub_bp, "/hello")
([]() {
@ -3395,7 +3395,7 @@ TEST_CASE("exception_handler")
CHECK(res.body.find("Hello world") != std::string::npos);
}
app.exception_handler([](crow::response& res) {
app.exception_handler([](response& res) {
try
{
throw;
@ -3451,31 +3451,31 @@ TEST_CASE("base64")
std::string sample_base64 = "Q3JvdyBBbGxvd3MgdXNlcnMgdG8gaGFuZGxlIHJlcXVlc3RzIHRoYXQgbWF5IG5vdCBjb21lIGZyb20gdGhlIG5ldHdvcmsuIFRoaXMgaXMgZG9uZSBieSBjYWxsaW5nIHRoZSBoYW5kbGUocmVxLCByZXMpIG1ldGhvZCBhbmQgcHJvdmlkaW5nIGEgcmVxdWVzdCBhbmQgcmVzcG9uc2Ugb2JqZWN0cy4gV2hpY2ggY2F1c2VzIGNyb3cgdG8gaWRlbnRpZnkgYW5kIHJ1biB0aGUgYXBwcm9wcmlhdGUgaGFuZGxlciwgcmV0dXJuaW5nIHRoZSByZXN1bHRpbmcgcmVzcG9uc2Uu";
CHECK(crow::utility::base64encode(sample_text, sample_text.length()) == sample_base64);
CHECK(crow::utility::base64encode(sample_bin, 6) == sample_bin_enc);
CHECK(crow::utility::base64encode_urlsafe(sample_bin, 6) == sample_bin_enc_url);
CHECK(crow::utility::base64encode(sample_bin1, 5) == sample_bin1_enc);
CHECK(crow::utility::base64encode(sample_bin2, 4) == sample_bin2_enc);
CHECK(utility::base64encode(sample_text, sample_text.length()) == sample_base64);
CHECK(utility::base64encode(sample_bin, 6) == sample_bin_enc);
CHECK(utility::base64encode_urlsafe(sample_bin, 6) == sample_bin_enc_url);
CHECK(utility::base64encode(sample_bin1, 5) == sample_bin1_enc);
CHECK(utility::base64encode(sample_bin2, 4) == sample_bin2_enc);
CHECK(crow::utility::base64decode(sample_base64) == sample_text);
CHECK(crow::utility::base64decode(sample_base64, sample_base64.length()) == sample_text);
CHECK(crow::utility::base64decode(sample_bin_enc, 8) == sample_bin_str);
CHECK(crow::utility::base64decode(sample_bin_enc_url, 8) == sample_bin_str);
CHECK(crow::utility::base64decode(sample_bin1_enc, 8) == sample_bin1_str);
CHECK(crow::utility::base64decode(sample_bin1_enc_np, 7) == sample_bin1_str);
CHECK(crow::utility::base64decode(sample_bin2_enc, 8) == sample_bin2_str);
CHECK(crow::utility::base64decode(sample_bin2_enc_np, 6) == sample_bin2_str);
CHECK(utility::base64decode(sample_base64) == sample_text);
CHECK(utility::base64decode(sample_base64, sample_base64.length()) == sample_text);
CHECK(utility::base64decode(sample_bin_enc, 8) == sample_bin_str);
CHECK(utility::base64decode(sample_bin_enc_url, 8) == sample_bin_str);
CHECK(utility::base64decode(sample_bin1_enc, 8) == sample_bin1_str);
CHECK(utility::base64decode(sample_bin1_enc_np, 7) == sample_bin1_str);
CHECK(utility::base64decode(sample_bin2_enc, 8) == sample_bin2_str);
CHECK(utility::base64decode(sample_bin2_enc_np, 6) == sample_bin2_str);
} // base64
TEST_CASE("normalize_path") {
CHECK(crow::utility::normalize_path("/abc/def") == "/abc/def/");
CHECK(crow::utility::normalize_path("path\\to\\directory") == "path/to/directory/");
CHECK(utility::normalize_path("/abc/def") == "/abc/def/");
CHECK(utility::normalize_path("path\\to\\directory") == "path/to/directory/");
} // normalize_path
TEST_CASE("sanitize_filename")
{
auto sanitize_filename = [](string s) {
crow::utility::sanitize_filename(s);
utility::sanitize_filename(s);
return s;
};
CHECK(sanitize_filename("abc/def") == "abc/def");
@ -3597,7 +3597,7 @@ TEST_CASE("task_timer")
bool a = false;
bool b = false;
crow::detail::task_timer timer(io_service);
detail::task_timer timer(io_service);
CHECK(timer.get_default_timeout() == 5);
timer.set_default_timeout(7);
CHECK(timer.get_default_timeout() == 7);
@ -3669,7 +3669,7 @@ TEST_CASE("http2_upgrade_is_ignored")
SimpleApp app;
CROW_ROUTE(app, "/echo").methods("POST"_method)
([](crow::request const& req) {
([](request const& req) {
return req.body;
});