refine the usage of build options

This commit is contained in:
Chunting Gu
2021-02-01 09:23:53 +08:00
parent 233aa5910c
commit 1b8b0b24ac
19 changed files with 48 additions and 45 deletions
+3 -3
View File
@@ -5,7 +5,7 @@
#include "webcc/logger.h"
#include "webcc/utility.h"
#if WEBCC_ENABLE_GZIP
#ifdef WEBCC_ENABLE_GZIP
#include "webcc/gzip.h"
#endif
@@ -15,7 +15,7 @@ namespace webcc {
// -----------------------------------------------------------------------------
#if WEBCC_ENABLE_GZIP
#ifdef WEBCC_ENABLE_GZIP
bool StringBody::Compress() {
if (compressed_) {
@@ -110,7 +110,7 @@ void FormBody::InitPayload() {
Payload FormBody::NextPayload(bool free_previous) {
Payload payload;
// Free previous payload.
if (free_previous) {
if (index_ > 0) {
+2 -2
View File
@@ -29,7 +29,7 @@ public:
return GetSize() == 0;
}
#if WEBCC_ENABLE_GZIP
#ifdef 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_;
}
#if WEBCC_ENABLE_GZIP
#ifdef 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") {
#if WEBCC_ENABLE_SSL
#ifdef WEBCC_ENABLE_SSL
socket_.reset(new SslSocket{ io_context_, ssl_verify_ });
DoConnect(request, "443");
#else
+2 -2
View File
@@ -19,7 +19,7 @@ void ClientSession::Accept(const std::string& content_types) {
}
}
#if WEBCC_ENABLE_GZIP
#ifdef WEBCC_ENABLE_GZIP
// Content-Encoding Tokens:
// (https://en.wikipedia.org/wiki/HTTP_compression)
@@ -117,7 +117,7 @@ ResponsePtr ClientSession::DoSend(RequestPtr request, bool stream) {
client->set_ssl_verify(ssl_verify_);
client->set_buffer_size(buffer_size_);
client->set_timeout(timeout_);
Error error = client->Request(request, !reuse, stream);
if (error) {
+1 -1
View File
@@ -51,7 +51,7 @@ public:
// Set content types to accept.
void Accept(const std::string& content_types);
#if WEBCC_ENABLE_GZIP
#ifdef 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
#if WEBCC_ENABLE_LOG
#ifdef 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@
#if WEBCC_ENABLE_LOG
#ifdef 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"
#if WEBCC_ENABLE_LOG
#ifdef 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"
#if WEBCC_ENABLE_LOG
#ifdef 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"
#if WEBCC_ENABLE_GZIP
#ifdef 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());
#if WEBCC_ENABLE_GZIP
#ifdef 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"
#if WEBCC_ENABLE_GZIP
#ifdef WEBCC_ENABLE_GZIP
#include "webcc/gzip.h"
#endif
@@ -32,7 +32,7 @@ RequestPtr RequestBuilder::operator()() {
if (body_) {
request->SetContentType(media_type_, charset_);
#if WEBCC_ENABLE_GZIP
#ifdef WEBCC_ENABLE_GZIP
if (gzip_ && body_->Compress()) {
request->SetHeader(headers::kContentEncoding, "gzip");
}
@@ -54,7 +54,7 @@ RequestPtr RequestBuilder::operator()() {
return request;
}
#if WEBCC_ENABLE_GZIP
#ifdef 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);
}
#if WEBCC_ENABLE_GZIP
#ifdef 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();
#if WEBCC_ENABLE_GZIP
#ifdef WEBCC_ENABLE_GZIP
// Compress the body data (only for string body).
// NOTE:
@@ -220,7 +220,7 @@ private:
// Persistent connection.
bool keep_alive_ = true;
#if WEBCC_ENABLE_GZIP
#ifdef 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"
#if WEBCC_ENABLE_GZIP
#ifdef WEBCC_ENABLE_GZIP
#include "webcc/gzip.h"
#endif
@@ -24,7 +24,7 @@ ResponsePtr ResponseBuilder::operator()() {
if (body_) {
response->SetContentType(media_type_, charset_);
#if WEBCC_ENABLE_GZIP
#ifdef 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();
#if WEBCC_ENABLE_GZIP
#ifdef 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_;
#if WEBCC_ENABLE_GZIP
#ifdef 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"
#if WEBCC_ENABLE_SSL
#ifdef WEBCC_ENABLE_SSL
#if (defined(_WIN32) || defined(_WIN64))
#include <windows.h>
@@ -75,7 +75,7 @@ bool Socket::Close() {
// -----------------------------------------------------------------------------
#if WEBCC_ENABLE_SSL
#ifdef WEBCC_ENABLE_SSL
#if (defined(_WIN32) || defined(_WIN64))
+2 -2
View File
@@ -8,7 +8,7 @@
#include "webcc/config.h"
#include "webcc/request.h"
#if WEBCC_ENABLE_SSL
#ifdef WEBCC_ENABLE_SSL
#include "boost/asio/ssl.hpp"
#endif // WEBCC_ENABLE_SSL
@@ -62,7 +62,7 @@ private:
// -----------------------------------------------------------------------------
#if WEBCC_ENABLE_SSL
#ifdef WEBCC_ENABLE_SSL
class SslSocket : public SocketBase {
public: