auto service = std::to_string(port);
if (getaddrinfo(host, service.c_str(), &hints, &result)) {
-#ifdef __linux__
+#if defined __linux__ && !defined __ANDROID__
res_init();
#endif
return INVALID_SOCKET;
std::string encoding = x.get_header_value("Content-Encoding");
std::unique_ptr<decompressor> decompressor;
- if (encoding.find("gzip") != std::string::npos ||
- encoding.find("deflate") != std::string::npos) {
+ if (encoding == "gzip" || encoding == "deflate") {
#ifdef CPPHTTPLIB_ZLIB_SUPPORT
decompressor = detail::make_unique<gzip_decompressor>();
#else
return query;
}
-std::string append_query_params(const char *path, const Params ¶ms) {
- std::string path_with_query = path;
- const static std::regex re("[^?]+\\?.*");
- auto delm = std::regex_match(path, re) ? '&' : '?';
- path_with_query += delm + params_to_query_str(params);
- return path_with_query;
-}
-
void parse_query_text(const std::string &s, Params ¶ms) {
std::set<std::string> cache;
split(s.data(), s.data() + s.size(), '&', [&](const char *b, const char *e) {
} // namespace detail
+std::string append_query_params(const char *path, const Params ¶ms) {
+ std::string path_with_query = path;
+ const static std::regex re("[^?]+\\?.*");
+ auto delm = std::regex_match(path, re) ? '&' : '?';
+ path_with_query += delm + detail::params_to_query_str(params);
+ return path_with_query;
+}
+
// Header utilities
std::pair<std::string, std::string> make_range_header(Ranges ranges) {
std::string field = "bytes=";
const Headers &headers, Progress progress) {
if (params.empty()) { return Get(path, headers); }
- std::string path_with_query = detail::append_query_params(path, params);
+ std::string path_with_query = append_query_params(path, params);
return Get(path_with_query.c_str(), headers, progress);
}
return Get(path, headers, response_handler, content_receiver, progress);
}
- std::string path_with_query = detail::append_query_params(path, params);
+ std::string path_with_query = append_query_params(path, params);
return Get(path_with_query.c_str(), headers, response_handler,
content_receiver, progress);
}
#include <unistd.h>
using socket_t = int;
+#ifndef INVALID_SOCKET
#define INVALID_SOCKET (-1)
+#endif
#endif //_WIN32
#include <algorithm>
using SocketOptions = std::function<void(socket_t sock)>;
-inline void default_socket_options(socket_t sock) {
- int yes = 1;
-#ifdef _WIN32
- setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<char *>(&yes),
- sizeof(yes));
- setsockopt(sock, SOL_SOCKET, SO_EXCLUSIVEADDRUSE,
- reinterpret_cast<char *>(&yes), sizeof(yes));
-#else
-#ifdef SO_REUSEPORT
- setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, reinterpret_cast<void *>(&yes),
- sizeof(yes));
-#else
- setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<void *>(&yes),
- sizeof(yes));
-#endif
-#endif
-}
+void default_socket_options(socket_t sock);
class Server {
public:
Compression,
};
-inline std::string to_string(const Error error) {
- switch (error) {
- case Error::Success: return "Success";
- case Error::Connection: return "Connection";
- case Error::BindIPAddress: return "BindIPAddress";
- case Error::Read: return "Read";
- case Error::Write: return "Write";
- case Error::ExceedRedirectCount: return "ExceedRedirectCount";
- case Error::Canceled: return "Canceled";
- case Error::SSLConnection: return "SSLConnection";
- case Error::SSLLoadingCerts: return "SSLLoadingCerts";
- case Error::SSLServerVerification: return "SSLServerVerification";
- case Error::UnsupportedMultipartBoundaryChars:
- return "UnsupportedMultipartBoundaryChars";
- case Error::Compression: return "Compression";
- case Error::Unknown: return "Unknown";
- default: break;
- }
-
- return "Invalid";
-}
+std::string to_string(const Error error);
-inline std::ostream &operator<<(std::ostream &os, const Error &obj) {
- os << to_string(obj);
- os << " (" << static_cast<std::underlying_type<Error>::type>(obj) << ')';
- return os;
-}
+std::ostream &operator<<(std::ostream &os, const Error &obj);
class Result {
public:
}
}
+inline void default_socket_options(socket_t sock) {
+ int yes = 1;
+#ifdef _WIN32
+ setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<char *>(&yes),
+ sizeof(yes));
+ setsockopt(sock, SOL_SOCKET, SO_EXCLUSIVEADDRUSE,
+ reinterpret_cast<char *>(&yes), sizeof(yes));
+#else
+#ifdef SO_REUSEPORT
+ setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, reinterpret_cast<void *>(&yes),
+ sizeof(yes));
+#else
+ setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<void *>(&yes),
+ sizeof(yes));
+#endif
+#endif
+}
+
template <class Rep, class Period>
inline Server &
Server::set_read_timeout(const std::chrono::duration<Rep, Period> &duration) {
return *this;
}
+inline std::string to_string(const Error error) {
+ switch (error) {
+ case Error::Success: return "Success";
+ case Error::Connection: return "Connection";
+ case Error::BindIPAddress: return "BindIPAddress";
+ case Error::Read: return "Read";
+ case Error::Write: return "Write";
+ case Error::ExceedRedirectCount: return "ExceedRedirectCount";
+ case Error::Canceled: return "Canceled";
+ case Error::SSLConnection: return "SSLConnection";
+ case Error::SSLLoadingCerts: return "SSLLoadingCerts";
+ case Error::SSLServerVerification: return "SSLServerVerification";
+ case Error::UnsupportedMultipartBoundaryChars:
+ return "UnsupportedMultipartBoundaryChars";
+ case Error::Compression: return "Compression";
+ case Error::Unknown: return "Unknown";
+ default: break;
+ }
+
+ return "Invalid";
+}
+
+inline std::ostream &operator<<(std::ostream &os, const Error &obj) {
+ os << to_string(obj);
+ os << " (" << static_cast<std::underlying_type<Error>::type>(obj) << ')';
+ return os;
+}
+
template <typename T>
inline T Result::get_request_header_value(const char *key, size_t id) const {
return detail::get_header_value<T>(request_headers_, key, id, 0);
* .h + .cc.
*/
+std::string append_query_params(const char *path, const Params ¶ms);
+
std::pair<std::string, std::string> make_range_header(Ranges ranges);
std::pair<std::string, std::string>