Drop the support of VS2013
This commit is contained in:
+9
-2
@@ -1,10 +1,17 @@
|
||||
#include "webcc/globals.h"
|
||||
|
||||
#include "boost/algorithm/string.hpp"
|
||||
#include "webcc/version.h"
|
||||
|
||||
namespace webcc {
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
namespace http {
|
||||
|
||||
const std::string& UserAgent() {
|
||||
static std::string s_user_agent = std::string("Webcc/") + WEBCC_VERSION;
|
||||
return s_user_agent;
|
||||
}
|
||||
|
||||
} // namespace http
|
||||
|
||||
const char* DescribeError(Error error) {
|
||||
switch (error) {
|
||||
|
||||
+6
-27
@@ -2,33 +2,8 @@
|
||||
#define WEBCC_GLOBALS_H_
|
||||
|
||||
#include <cassert>
|
||||
#include <exception>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "webcc/version.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Macros
|
||||
|
||||
// Does the compiler support "= default" for move copy constructor and
|
||||
// move assignment operator?
|
||||
#ifdef _MSC_VER
|
||||
#if _MSC_VER <= 1800 // VS 2013
|
||||
#define WEBCC_DEFAULT_MOVE_COPY_ASSIGN 0
|
||||
#else
|
||||
#define WEBCC_DEFAULT_MOVE_COPY_ASSIGN 1
|
||||
#endif // _MSC_VER <= 1800
|
||||
#else
|
||||
#define WEBCC_DEFAULT_MOVE_COPY_ASSIGN 1
|
||||
#endif // _MSC_VER
|
||||
|
||||
// Explicitly declare the copy constructor and assignment operator as deleted.
|
||||
#define WEBCC_DELETE_COPY_ASSIGN(TypeName) \
|
||||
TypeName(const TypeName&) = delete; \
|
||||
TypeName& operator=(const TypeName&) = delete;
|
||||
|
||||
// Default user agent.
|
||||
#define USER_AGENT "Webcc/" WEBCC_VERSION
|
||||
|
||||
namespace webcc {
|
||||
|
||||
@@ -120,6 +95,9 @@ const char* const kUtf8 = "utf-8";
|
||||
|
||||
} // namespace charsets
|
||||
|
||||
// Return default user agent for HTTP headers.
|
||||
const std::string& UserAgent();
|
||||
|
||||
} // namespace http
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -156,7 +134,8 @@ public:
|
||||
explicit Exception(Error error = kNoError, bool timeout = false,
|
||||
const std::string& details = "");
|
||||
|
||||
const char* what() const override {
|
||||
// Note that `noexcept` is required by GCC.
|
||||
const char* what() const noexcept override {
|
||||
return msg_.c_str();
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,8 @@ public:
|
||||
|
||||
virtual ~HttpClientBase() = default;
|
||||
|
||||
WEBCC_DELETE_COPY_ASSIGN(HttpClientBase);
|
||||
HttpClientBase(const HttpClientBase&) = delete;
|
||||
HttpClientBase& operator=(const HttpClientBase&) = delete;
|
||||
|
||||
// Set the timeout seconds for reading response.
|
||||
// The |seconds| is only effective when greater than 0.
|
||||
|
||||
@@ -82,7 +82,7 @@ HttpResponsePtr HttpClientSession::Post(const std::string& url,
|
||||
|
||||
void HttpClientSession::InitHeaders() {
|
||||
// NOTE: C++11 requires a space between literal and string macro.
|
||||
headers_.Add(http::headers::kUserAgent, USER_AGENT);
|
||||
headers_.Add(http::headers::kUserAgent, http::UserAgent());
|
||||
|
||||
// TODO: Support gzip, deflate
|
||||
headers_.Add(http::headers::kAcceptEncoding, "identity");
|
||||
|
||||
@@ -26,7 +26,8 @@ public:
|
||||
|
||||
~HttpConnection() = default;
|
||||
|
||||
WEBCC_DELETE_COPY_ASSIGN(HttpConnection);
|
||||
HttpConnection(const HttpConnection&) = delete;
|
||||
HttpConnection& operator=(const HttpConnection&) = delete;
|
||||
|
||||
const HttpRequest& request() const {
|
||||
return request_;
|
||||
|
||||
+2
-1
@@ -16,7 +16,8 @@ public:
|
||||
|
||||
virtual ~HttpParser() = default;
|
||||
|
||||
WEBCC_DELETE_COPY_ASSIGN(HttpParser);
|
||||
HttpParser(const HttpParser&) = delete;
|
||||
HttpParser& operator=(const HttpParser&) = delete;
|
||||
|
||||
bool finished() const { return finished_; }
|
||||
|
||||
|
||||
@@ -24,42 +24,9 @@ public:
|
||||
HttpRequestArgs(const HttpRequestArgs&) = default;
|
||||
HttpRequestArgs& operator=(const HttpRequestArgs&) = default;
|
||||
|
||||
#if WEBCC_DEFAULT_MOVE_COPY_ASSIGN
|
||||
|
||||
HttpRequestArgs(HttpRequestArgs&&) = default;
|
||||
HttpRequestArgs& operator=(HttpRequestArgs&&) = default;
|
||||
|
||||
#else
|
||||
|
||||
HttpRequestArgs(HttpRequestArgs&& rhs)
|
||||
: method_(std::move(rhs.method_)),
|
||||
url_(std::move(rhs.url_)),
|
||||
parameters_(std::move(rhs.parameters_)),
|
||||
data_(std::move(rhs.data_)),
|
||||
json_(rhs.json_),
|
||||
headers_(std::move(rhs.headers_)),
|
||||
ssl_verify_(rhs.ssl_verify_),
|
||||
buffer_size_(rhs.buffer_size_) {
|
||||
LOG_VERB("HttpRequestArgs(&&)");
|
||||
}
|
||||
|
||||
HttpRequestArgs& operator=(HttpRequestArgs&& rhs) {
|
||||
if (&rhs != this) {
|
||||
method_ = std::move(rhs.method_);
|
||||
url_ = std::move(rhs.url_);
|
||||
parameters_ = std::move(rhs.parameters_);
|
||||
data_ = std::move(rhs.data_);
|
||||
json_ = rhs.json_;
|
||||
headers_ = std::move(rhs.headers_);
|
||||
ssl_verify_ = rhs.ssl_verify_;
|
||||
buffer_size_ = buffer_size_;
|
||||
}
|
||||
LOG_VERB("HttpRequestArgs& operator=(&&)");
|
||||
return *this;
|
||||
}
|
||||
|
||||
#endif // WEBCC_DEFAULT_MOVE_COPY_ASSIGN
|
||||
|
||||
HttpRequestArgs&& method(const std::string& method) {
|
||||
method_ = method;
|
||||
return std::move(*this);
|
||||
|
||||
@@ -20,7 +20,8 @@ public:
|
||||
HttpRequestHandler() = default;
|
||||
virtual ~HttpRequestHandler() = default;
|
||||
|
||||
WEBCC_DELETE_COPY_ASSIGN(HttpRequestHandler);
|
||||
HttpRequestHandler(const HttpRequestHandler&) = delete;
|
||||
HttpRequestHandler& operator=(const HttpRequestHandler&) = delete;
|
||||
|
||||
// Put the connection into the queue.
|
||||
void Enqueue(HttpConnectionPtr connection);
|
||||
|
||||
@@ -60,7 +60,7 @@ const std::string& ToString(int status) {
|
||||
bool HttpResponse::Prepare() {
|
||||
start_line_ = status_strings::ToString(status_);
|
||||
|
||||
SetHeader("Server", USER_AGENT);
|
||||
SetHeader("Server", http::UserAgent());
|
||||
SetHeader("Date", GetHttpDateTimestamp());
|
||||
|
||||
return true;
|
||||
|
||||
+2
-1
@@ -22,7 +22,8 @@ public:
|
||||
|
||||
virtual ~HttpServer() = default;
|
||||
|
||||
WEBCC_DELETE_COPY_ASSIGN(HttpServer);
|
||||
HttpServer(const HttpServer&) = delete;
|
||||
HttpServer& operator=(const HttpServer&) = delete;
|
||||
|
||||
// Run the server's io_service loop.
|
||||
void Run();
|
||||
|
||||
@@ -14,7 +14,8 @@ class RestServiceManager {
|
||||
public:
|
||||
RestServiceManager() = default;
|
||||
|
||||
WEBCC_DELETE_COPY_ASSIGN(RestServiceManager);
|
||||
RestServiceManager(const RestServiceManager&) = delete;
|
||||
RestServiceManager& operator=(const RestServiceManager&) = delete;
|
||||
|
||||
// Add a service and bind it with the given URL.
|
||||
// The |url| should start with "/" and will be treated as a regular expression
|
||||
|
||||
@@ -15,7 +15,14 @@ SoapClient::SoapClient(const std::string& host, const std::string& port,
|
||||
: host_(host), port_(port), soap_version_(soap_version),
|
||||
http_client_(buffer_size),
|
||||
format_raw_(true), error_(kNoError) {
|
||||
AdjustHostPort(host_, port_);
|
||||
// Try to extract port from host if it's empty.
|
||||
if (port_.empty()) {
|
||||
std::size_t i = host_.find_last_of(':');
|
||||
if (i != std::string::npos) {
|
||||
port_ = host_.substr(i + 1);
|
||||
host_ = host_.substr(0, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool SoapClient::Request(const std::string& operation,
|
||||
|
||||
+2
-1
@@ -21,7 +21,8 @@ public:
|
||||
|
||||
~SoapClient() = default;
|
||||
|
||||
WEBCC_DELETE_COPY_ASSIGN(SoapClient);
|
||||
SoapClient(const SoapClient&) = delete;
|
||||
SoapClient& operator=(const SoapClient&) = delete;
|
||||
|
||||
void SetTimeout(int seconds) {
|
||||
http_client_.SetTimeout(seconds);
|
||||
|
||||
@@ -46,29 +46,9 @@ public:
|
||||
as_cdata_(false) {
|
||||
}
|
||||
|
||||
#if WEBCC_DEFAULT_MOVE_COPY_ASSIGN
|
||||
|
||||
SoapParameter(SoapParameter&&) = default;
|
||||
SoapParameter& operator=(SoapParameter&&) = default;
|
||||
|
||||
#else
|
||||
|
||||
SoapParameter(SoapParameter&& rhs)
|
||||
: key_(std::move(rhs.key_)), value_(std::move(rhs.value_)),
|
||||
as_cdata_(rhs.as_cdata_) {
|
||||
}
|
||||
|
||||
SoapParameter& operator=(SoapParameter&& rhs) {
|
||||
if (&rhs != this) {
|
||||
key_ = std::move(rhs.key_);
|
||||
value_ = std::move(rhs.value_);
|
||||
as_cdata_ = rhs.as_cdata_;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
#endif // WEBCC_DEFAULT_MOVE_COPY_ASSIGN
|
||||
|
||||
const std::string& key() const { return key_; }
|
||||
const std::string& value() const { return value_; }
|
||||
|
||||
|
||||
-25
@@ -61,34 +61,9 @@ public:
|
||||
|
||||
explicit Url(const std::string& str, bool decode = true);
|
||||
|
||||
#if WEBCC_DEFAULT_MOVE_COPY_ASSIGN
|
||||
|
||||
Url(Url&&) = default;
|
||||
Url& operator=(Url&&) = default;
|
||||
|
||||
#else
|
||||
|
||||
Url(Url&& rhs)
|
||||
: scheme_(std::move(rhs.scheme_)),
|
||||
host_(std::move(rhs.host_)),
|
||||
port_(std::move(rhs.port_)),
|
||||
path_(std::move(rhs.path_)),
|
||||
query_(std::move(rhs.query_)) {
|
||||
}
|
||||
|
||||
Url& operator=(Url&& rhs) {
|
||||
if (&rhs != this) {
|
||||
scheme_ = std::move(rhs.scheme_);
|
||||
host_ = std::move(rhs.host_);
|
||||
port_ = std::move(rhs.port_);
|
||||
path_ = std::move(rhs.path_);
|
||||
query_ = std::move(rhs.query_);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
#endif // WEBCC_DEFAULT_MOVE_COPY_ASSIGN
|
||||
|
||||
void Init(const std::string& str, bool decode = true, bool clear = true);
|
||||
|
||||
const std::string& scheme() const {
|
||||
|
||||
@@ -12,16 +12,6 @@ using tcp = boost::asio::ip::tcp;
|
||||
|
||||
namespace webcc {
|
||||
|
||||
void AdjustHostPort(std::string& host, std::string& port) {
|
||||
if (port.empty()) {
|
||||
std::size_t i = host.find_last_of(':');
|
||||
if (i != std::string::npos) {
|
||||
port = host.substr(i + 1);
|
||||
host = host.substr(0, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PrintEndpoint(std::ostream& ostream, const TcpEndpoint& endpoint) {
|
||||
ostream << endpoint;
|
||||
if (endpoint.protocol() == tcp::v4()) {
|
||||
|
||||
@@ -9,9 +9,6 @@
|
||||
|
||||
namespace webcc {
|
||||
|
||||
// If |port| is empty, try to extract it from |host| (separated by ':').
|
||||
void AdjustHostPort(std::string& host, std::string& port);
|
||||
|
||||
typedef boost::asio::ip::tcp::endpoint TcpEndpoint;
|
||||
typedef boost::asio::ip::tcp::resolver::results_type TcpEndpoints;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user