@@ -582,23 +582,7 @@ using Logger = std::function<void(const Request &, const Response &)>;
582582
583583using SocketOptions = std::function<void (socket_t sock)>;
584584
585- inline void default_socket_options (socket_t sock) {
586- int yes = 1 ;
587- #ifdef _WIN32
588- setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast <char *>(&yes),
589- sizeof (yes));
590- setsockopt (sock, SOL_SOCKET, SO_EXCLUSIVEADDRUSE,
591- reinterpret_cast <char *>(&yes), sizeof (yes));
592- #else
593- #ifdef SO_REUSEPORT
594- setsockopt (sock, SOL_SOCKET, SO_REUSEPORT, reinterpret_cast <void *>(&yes),
595- sizeof (yes));
596- #else
597- setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast <void *>(&yes),
598- sizeof (yes));
599- #endif
600- #endif
601- }
585+ void default_socket_options (socket_t sock);
602586
603587class Server {
604588public:
@@ -800,33 +784,9 @@ enum class Error {
800784 Compression,
801785};
802786
803- inline std::string to_string (const Error error) {
804- switch (error) {
805- case Error::Success: return " Success" ;
806- case Error::Connection: return " Connection" ;
807- case Error::BindIPAddress: return " BindIPAddress" ;
808- case Error::Read: return " Read" ;
809- case Error::Write: return " Write" ;
810- case Error::ExceedRedirectCount: return " ExceedRedirectCount" ;
811- case Error::Canceled: return " Canceled" ;
812- case Error::SSLConnection: return " SSLConnection" ;
813- case Error::SSLLoadingCerts: return " SSLLoadingCerts" ;
814- case Error::SSLServerVerification: return " SSLServerVerification" ;
815- case Error::UnsupportedMultipartBoundaryChars:
816- return " UnsupportedMultipartBoundaryChars" ;
817- case Error::Compression: return " Compression" ;
818- case Error::Unknown: return " Unknown" ;
819- default : break ;
820- }
821-
822- return " Invalid" ;
823- }
787+ std::string to_string (const Error error);
824788
825- inline std::ostream &operator <<(std::ostream &os, const Error &obj) {
826- os << to_string (obj);
827- os << " (" << static_cast <std::underlying_type<Error>::type>(obj) << ' )' ;
828- return os;
829- }
789+ std::ostream &operator <<(std::ostream &os, const Error &obj);
830790
831791class Result {
832792public:
@@ -1546,6 +1506,24 @@ inline ssize_t Stream::write_format(const char *fmt, const Args &... args) {
15461506 }
15471507}
15481508
1509+ inline void default_socket_options (socket_t sock) {
1510+ int yes = 1 ;
1511+ #ifdef _WIN32
1512+ setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast <char *>(&yes),
1513+ sizeof (yes));
1514+ setsockopt (sock, SOL_SOCKET, SO_EXCLUSIVEADDRUSE,
1515+ reinterpret_cast <char *>(&yes), sizeof (yes));
1516+ #else
1517+ #ifdef SO_REUSEPORT
1518+ setsockopt (sock, SOL_SOCKET, SO_REUSEPORT, reinterpret_cast <void *>(&yes),
1519+ sizeof (yes));
1520+ #else
1521+ setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast <void *>(&yes),
1522+ sizeof (yes));
1523+ #endif
1524+ #endif
1525+ }
1526+
15491527template <class Rep , class Period >
15501528inline Server &
15511529Server::set_read_timeout (const std::chrono::duration<Rep, Period> &duration) {
@@ -1570,6 +1548,34 @@ Server::set_idle_interval(const std::chrono::duration<Rep, Period> &duration) {
15701548 return *this ;
15711549}
15721550
1551+ inline std::string to_string (const Error error) {
1552+ switch (error) {
1553+ case Error::Success: return " Success" ;
1554+ case Error::Connection: return " Connection" ;
1555+ case Error::BindIPAddress: return " BindIPAddress" ;
1556+ case Error::Read: return " Read" ;
1557+ case Error::Write: return " Write" ;
1558+ case Error::ExceedRedirectCount: return " ExceedRedirectCount" ;
1559+ case Error::Canceled: return " Canceled" ;
1560+ case Error::SSLConnection: return " SSLConnection" ;
1561+ case Error::SSLLoadingCerts: return " SSLLoadingCerts" ;
1562+ case Error::SSLServerVerification: return " SSLServerVerification" ;
1563+ case Error::UnsupportedMultipartBoundaryChars:
1564+ return " UnsupportedMultipartBoundaryChars" ;
1565+ case Error::Compression: return " Compression" ;
1566+ case Error::Unknown: return " Unknown" ;
1567+ default : break ;
1568+ }
1569+
1570+ return " Invalid" ;
1571+ }
1572+
1573+ inline std::ostream &operator <<(std::ostream &os, const Error &obj) {
1574+ os << to_string (obj);
1575+ os << " (" << static_cast <std::underlying_type<Error>::type>(obj) << ' )' ;
1576+ return os;
1577+ }
1578+
15731579template <typename T>
15741580inline T Result::get_request_header_value (const char *key, size_t id) const {
15751581 return detail::get_header_value<T>(request_headers_, key, id, 0 );
@@ -1620,6 +1626,8 @@ Client::set_write_timeout(const std::chrono::duration<Rep, Period> &duration) {
16201626 * .h + .cc.
16211627 */
16221628
1629+ std::string append_query_params (const char *path, const Params ¶ms);
1630+
16231631std::pair<std::string, std::string> make_range_header (Ranges ranges);
16241632
16251633std::pair<std::string, std::string>
@@ -3503,14 +3511,6 @@ inline std::string params_to_query_str(const Params ¶ms) {
35033511 return query;
35043512}
35053513
3506- inline std::string append_query_params (const char *path, const Params ¶ms) {
3507- std::string path_with_query = path;
3508- const static std::regex re (" [^?]+\\ ?.*" );
3509- auto delm = std::regex_match (path, re) ? ' &' : ' ?' ;
3510- path_with_query += delm + params_to_query_str (params);
3511- return path_with_query;
3512- }
3513-
35143514inline void parse_query_text (const std::string &s, Params ¶ms) {
35153515 std::set<std::string> cache;
35163516 split (s.data (), s.data () + s.size (), ' &' , [&](const char *b, const char *e) {
@@ -4144,6 +4144,14 @@ class ContentProviderAdapter {
41444144
41454145} // namespace detail
41464146
4147+ inline std::string append_query_params (const char *path, const Params ¶ms) {
4148+ std::string path_with_query = path;
4149+ const static std::regex re (" [^?]+\\ ?.*" );
4150+ auto delm = std::regex_match (path, re) ? ' &' : ' ?' ;
4151+ path_with_query += delm + detail::params_to_query_str (params);
4152+ return path_with_query;
4153+ }
4154+
41474155// Header utilities
41484156inline std::pair<std::string, std::string> make_range_header (Ranges ranges) {
41494157 std::string field = " bytes=" ;
@@ -6237,7 +6245,7 @@ inline Result ClientImpl::Get(const char *path, const Params ¶ms,
62376245 const Headers &headers, Progress progress) {
62386246 if (params.empty ()) { return Get (path, headers); }
62396247
6240- std::string path_with_query = detail:: append_query_params (path, params);
6248+ std::string path_with_query = append_query_params (path, params);
62416249 return Get (path_with_query.c_str (), headers, progress);
62426250}
62436251
@@ -6257,7 +6265,7 @@ inline Result ClientImpl::Get(const char *path, const Params ¶ms,
62576265 return Get (path, headers, response_handler, content_receiver, progress);
62586266 }
62596267
6260- std::string path_with_query = detail:: append_query_params (path, params);
6268+ std::string path_with_query = append_query_params (path, params);
62616269 return Get (path_with_query.c_str (), headers, response_handler,
62626270 content_receiver, progress);
62636271}
0 commit comments