fix build option issues; refine cmake

This commit is contained in:
Chunting Gu
2021-02-05 14:12:26 +08:00
parent 1c35b97654
commit 7f345b7a4e
26 changed files with 70 additions and 65 deletions
+2 -2
View File
@@ -1,10 +1,10 @@
# webcc
# Don't use any deprecated definitions (e.g., io_service).
add_definitions(-DBOOST_ASIO_NO_DEPRECATED)
add_compile_definitions(BOOST_ASIO_NO_DEPRECATED)
if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
endif()
configure_file(
+2 -2
View File
@@ -5,7 +5,7 @@
#include "webcc/logger.h"
#include "webcc/utility.h"
#ifdef WEBCC_ENABLE_GZIP
#if WEBCC_ENABLE_GZIP
#include "webcc/gzip.h"
#endif
@@ -15,7 +15,7 @@ namespace webcc {
// -----------------------------------------------------------------------------
#ifdef WEBCC_ENABLE_GZIP
#if WEBCC_ENABLE_GZIP
bool StringBody::Compress() {
if (compressed_) {
+2 -2
View File
@@ -29,7 +29,7 @@ public:
return GetSize() == 0;
}
#ifdef WEBCC_ENABLE_GZIP
#if WEBCC_ENABLE_GZIP
// Compress the data with Gzip.
// If data size <= threshold (1400 bytes), no compression will be taken
@@ -90,7 +90,7 @@ public:
return compressed_;
}
#ifdef WEBCC_ENABLE_GZIP
#if WEBCC_ENABLE_GZIP
bool Compress() override;
+1 -1
View File
@@ -78,7 +78,7 @@ void Client::Close() {
void Client::Connect(RequestPtr request) {
if (request->url().scheme() == "https") {
#ifdef WEBCC_ENABLE_SSL
#if WEBCC_ENABLE_SSL
socket_.reset(new SslSocket{ io_context_, ssl_verify_ });
DoConnect(request, "443");
#else
+1 -1
View File
@@ -19,7 +19,7 @@ void ClientSession::Accept(const std::string& content_types) {
}
}
#ifdef WEBCC_ENABLE_GZIP
#if WEBCC_ENABLE_GZIP
// Content-Encoding Tokens:
// (https://en.wikipedia.org/wiki/HTTP_compression)
+1 -1
View File
@@ -51,7 +51,7 @@ public:
// Set content types to accept.
void Accept(const std::string& content_types);
#ifdef WEBCC_ENABLE_GZIP
#if WEBCC_ENABLE_GZIP
// Accept Gzip compressed response data or not.
void AcceptGzip(bool gzip = true);
+1 -1
View File
@@ -6,7 +6,7 @@
// Set 1/0 to enable/disable logging.
#define WEBCC_ENABLE_LOG 1
#ifdef WEBCC_ENABLE_LOG
#if WEBCC_ENABLE_LOG
// 0:VERB, 1:INFO, 2:USER, 3:WARN or 4:ERRO
#define WEBCC_LOG_LEVEL 2
#endif
+1 -1
View File
@@ -8,7 +8,7 @@
// Set 1/0 to enable/disable logging.
#define WEBCC_ENABLE_LOG @WEBCC_ENABLE_LOG@
#ifdef WEBCC_ENABLE_LOG
#if WEBCC_ENABLE_LOG
// 0:VERB, 1:INFO, 2:USER, 3:WARN or 4:ERRO
#define WEBCC_LOG_LEVEL @WEBCC_LOG_LEVEL@
#endif // WEBCC_ENABLE_LOG
+1 -1
View File
@@ -1,6 +1,6 @@
#include "webcc/logger.h"
#ifdef WEBCC_ENABLE_LOG
#if WEBCC_ENABLE_LOG
#include <cassert>
#include <chrono>
+1 -1
View File
@@ -4,7 +4,7 @@
// This file was generated from "config.h.in" by CMake.
#include "webcc/config.h"
#ifdef WEBCC_ENABLE_LOG
#if WEBCC_ENABLE_LOG
#include <cstring> // for strrchr()
#include <string>
+2 -2
View File
@@ -7,7 +7,7 @@
#include "webcc/string.h"
#include "webcc/utility.h"
#ifdef WEBCC_ENABLE_GZIP
#if WEBCC_ENABLE_GZIP
#include "webcc/gzip.h"
#endif
@@ -48,7 +48,7 @@ bool StringBodyHandler::Finish() {
auto body = std::make_shared<StringBody>(std::move(content_), IsCompressed());
#ifdef WEBCC_ENABLE_GZIP
#if WEBCC_ENABLE_GZIP
LOG_INFO("Decompress the HTTP content...");
if (!body->Decompress()) {
LOG_ERRO("Cannot decompress the HTTP content!");
+3 -3
View File
@@ -5,7 +5,7 @@
#include "webcc/string.h"
#include "webcc/utility.h"
#ifdef WEBCC_ENABLE_GZIP
#if WEBCC_ENABLE_GZIP
#include "webcc/gzip.h"
#endif
@@ -32,7 +32,7 @@ RequestPtr RequestBuilder::operator()() {
if (body_) {
request->SetContentType(media_type_, charset_);
#ifdef WEBCC_ENABLE_GZIP
#if WEBCC_ENABLE_GZIP
if (gzip_ && body_->Compress()) {
request->SetHeader(headers::kContentEncoding, "gzip");
}
@@ -54,7 +54,7 @@ RequestPtr RequestBuilder::operator()() {
return request;
}
#ifdef WEBCC_ENABLE_GZIP
#if WEBCC_ENABLE_GZIP
// Accept Gzip compressed response data or not.
RequestBuilder& RequestBuilder::AcceptGzip(bool gzip) {
+3 -3
View File
@@ -124,7 +124,7 @@ public:
return Header(headers::kAccept, content_types);
}
#ifdef WEBCC_ENABLE_GZIP
#if WEBCC_ENABLE_GZIP
// Accept Gzip compressed response data or not.
RequestBuilder& AcceptGzip(bool gzip = true);
@@ -179,7 +179,7 @@ public:
// Add the `Date` header to the request.
RequestBuilder& Date();
#ifdef WEBCC_ENABLE_GZIP
#if WEBCC_ENABLE_GZIP
// Compress the body data (only for string body).
// NOTE:
@@ -220,7 +220,7 @@ private:
// Persistent connection.
bool keep_alive_ = true;
#ifdef WEBCC_ENABLE_GZIP
#if WEBCC_ENABLE_GZIP
bool gzip_ = false;
#endif // WEBCC_ENABLE_GZIP
};
+2 -2
View File
@@ -4,7 +4,7 @@
#include "webcc/logger.h"
#include "webcc/utility.h"
#ifdef WEBCC_ENABLE_GZIP
#if WEBCC_ENABLE_GZIP
#include "webcc/gzip.h"
#endif
@@ -24,7 +24,7 @@ ResponsePtr ResponseBuilder::operator()() {
if (body_) {
response->SetContentType(media_type_, charset_);
#ifdef WEBCC_ENABLE_GZIP
#if WEBCC_ENABLE_GZIP
if (gzip_) {
// Don't try to compress the response if the request doesn't accept gzip.
if (request_ && request_->AcceptEncodingGzip()) {
+2 -2
View File
@@ -109,7 +109,7 @@ public:
// Add the `Date` header to the response.
ResponseBuilder& Date();
#ifdef WEBCC_ENABLE_GZIP
#if WEBCC_ENABLE_GZIP
ResponseBuilder& Gzip(bool gzip = true) {
gzip_ = gzip;
return *this;
@@ -131,7 +131,7 @@ private:
// Character set of the body (e.g., "utf-8").
std::string charset_;
#ifdef WEBCC_ENABLE_GZIP
#if WEBCC_ENABLE_GZIP
// Compress the body data (only for string body).
bool gzip_ = false;
#endif // WEBCC_ENABLE_GZIP
+2 -2
View File
@@ -1,6 +1,6 @@
#include "webcc/socket.h"
#ifdef WEBCC_ENABLE_SSL
#if WEBCC_ENABLE_SSL
#if (defined(_WIN32) || defined(_WIN64))
#include <windows.h>
@@ -75,7 +75,7 @@ bool Socket::Close() {
// -----------------------------------------------------------------------------
#ifdef WEBCC_ENABLE_SSL
#if WEBCC_ENABLE_SSL
#if (defined(_WIN32) || defined(_WIN64))
+2 -2
View File
@@ -8,7 +8,7 @@
#include "webcc/config.h"
#include "webcc/request.h"
#ifdef WEBCC_ENABLE_SSL
#if WEBCC_ENABLE_SSL
#include "boost/asio/ssl.hpp"
#endif // WEBCC_ENABLE_SSL
@@ -62,7 +62,7 @@ private:
// -----------------------------------------------------------------------------
#ifdef WEBCC_ENABLE_SSL
#if WEBCC_ENABLE_SSL
class SslSocket : public SocketBase {
public: