From 964d21748ab0497e318d6d589520753e091084b5 Mon Sep 17 00:00:00 2001 From: Chunting Gu Date: Tue, 13 Nov 2018 13:00:23 +0800 Subject: [PATCH] Rename BasicRestClient to RestBasicClient. --- webcc/CMakeLists.txt | 4 ++-- webcc/{basic_rest_client.h => rest_basic_client.h} | 14 +++++++------- webcc/rest_client.h | 4 ++-- webcc/rest_request_handler.cc | 2 +- webcc/rest_ssl_client.h | 4 ++-- webcc/url.cc | 8 ++++++-- webcc/url.h | 2 +- 7 files changed, 21 insertions(+), 17 deletions(-) rename webcc/{basic_rest_client.h => rest_basic_client.h} (91%) diff --git a/webcc/CMakeLists.txt b/webcc/CMakeLists.txt index cd52f30..6055dc1 100644 --- a/webcc/CMakeLists.txt +++ b/webcc/CMakeLists.txt @@ -9,7 +9,6 @@ endif() include(GNUInstallDirs) set(HEADERS - version.h globals.h http_async_client.h http_client.h @@ -24,8 +23,8 @@ set(HEADERS http_server.h logger.h queue.h - basic_rest_client.h rest_async_client.h + rest_basic_client.h rest_client.h rest_request_handler.h rest_server.h @@ -33,6 +32,7 @@ set(HEADERS rest_service_manager.h url.h utility.h + version.h ) set(SOURCES diff --git a/webcc/basic_rest_client.h b/webcc/rest_basic_client.h similarity index 91% rename from webcc/basic_rest_client.h rename to webcc/rest_basic_client.h index f269abb..bafb6ee 100644 --- a/webcc/basic_rest_client.h +++ b/webcc/rest_basic_client.h @@ -1,5 +1,5 @@ -#ifndef WEBCC_BASIC_REST_CLIENT_H_ -#define WEBCC_BASIC_REST_CLIENT_H_ +#ifndef WEBCC_REST_BASIC_CLIENT_H_ +#define WEBCC_REST_BASIC_CLIENT_H_ #include #include @@ -12,11 +12,11 @@ namespace webcc { template -class BasicRestClient { +class RestBasicClient { public: // If |port| is empty, |host| will be checked to see if it contains port or // not (separated by ':'). - explicit BasicRestClient(const std::string& host, + explicit RestBasicClient(const std::string& host, const std::string& port = "") : host_(host), port_(port) { if (port_.empty()) { @@ -28,9 +28,9 @@ class BasicRestClient { } } - ~BasicRestClient() = default; + ~RestBasicClient() = default; - WEBCC_DELETE_COPY_ASSIGN(BasicRestClient); + WEBCC_DELETE_COPY_ASSIGN(RestBasicClient); void SetTimeout(int seconds) { http_client_.SetTimeout(seconds); @@ -120,4 +120,4 @@ class BasicRestClient { } // namespace webcc -#endif // WEBCC_BASIC_REST_CLIENT_H_ +#endif // WEBCC_REST_BASIC_CLIENT_H_ diff --git a/webcc/rest_client.h b/webcc/rest_client.h index b125ba8..4f7630b 100644 --- a/webcc/rest_client.h +++ b/webcc/rest_client.h @@ -1,12 +1,12 @@ #ifndef WEBCC_REST_CLIENT_H_ #define WEBCC_REST_CLIENT_H_ -#include "webcc/basic_rest_client.h" +#include "webcc/rest_basic_client.h" #include "webcc/http_client.h" namespace webcc { -typedef BasicRestClient RestClient; +typedef RestBasicClient RestClient; } // namespace webcc diff --git a/webcc/rest_request_handler.cc b/webcc/rest_request_handler.cc index 322020d..613d761 100644 --- a/webcc/rest_request_handler.cc +++ b/webcc/rest_request_handler.cc @@ -18,7 +18,7 @@ void RestRequestHandler::HandleSession(HttpSessionPtr session) { Url url(http_request.url(), /*decode*/true); - if (!url.IsValid()) { + if (!url.IsPathValid()) { session->SendResponse(HttpStatus::kBadRequest); return; } diff --git a/webcc/rest_ssl_client.h b/webcc/rest_ssl_client.h index 4420f61..9181a83 100644 --- a/webcc/rest_ssl_client.h +++ b/webcc/rest_ssl_client.h @@ -1,12 +1,12 @@ #ifndef WEBCC_REST_SSL_CLIENT_H_ #define WEBCC_REST_SSL_CLIENT_H_ -#include "webcc/basic_rest_client.h" +#include "webcc/rest_basic_client.h" #include "webcc/http_ssl_client.h" namespace webcc { -typedef BasicRestClient RestSslClient; +typedef RestBasicClient RestSslClient; } // namespace webcc diff --git a/webcc/url.cc b/webcc/url.cc index 01d726a..63e85bc 100644 --- a/webcc/url.cc +++ b/webcc/url.cc @@ -258,8 +258,12 @@ Url::Url(const std::string& str, bool decode) { } } -bool Url::IsValid() const { - return !path_.empty(); +bool Url::IsPathValid() const { + // URL path must be absolute. + if (path_.empty() || path_[0] != '/') { + return false; + } + return true; } std::vector Url::SplitPath(const std::string& path) { diff --git a/webcc/url.h b/webcc/url.h index 94de7a4..a0dc5f5 100644 --- a/webcc/url.h +++ b/webcc/url.h @@ -62,7 +62,7 @@ class Url { Url() = default; Url(const std::string& str, bool decode); - bool IsValid() const; + bool IsPathValid() const; const std::string& path() const { return path_;