From f08e090bdab59abdf6ec0d210664dd9eb7a335ea Mon Sep 17 00:00:00 2001 From: alesapin Date: Tue, 20 Nov 2018 20:21:32 +0300 Subject: [PATCH] Better uri scheme check and fix in poco submodule --- contrib/poco | 2 +- dbms/src/Common/ErrorCodes.cpp | 2 +- dbms/src/IO/HTTPCommon.cpp | 15 +++++++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/contrib/poco b/contrib/poco index d7a4383c4d8..20c1d877773 160000 --- a/contrib/poco +++ b/contrib/poco @@ -1 +1 @@ -Subproject commit d7a4383c4d85b51938b62ed5812bc0935245edb3 +Subproject commit 20c1d877773b6a672f1bbfe3290dfea42a117ed5 diff --git a/dbms/src/Common/ErrorCodes.cpp b/dbms/src/Common/ErrorCodes.cpp index 3bace270cac..3560bcee9af 100644 --- a/dbms/src/Common/ErrorCodes.cpp +++ b/dbms/src/Common/ErrorCodes.cpp @@ -396,7 +396,7 @@ namespace ErrorCodes extern const int MULTIPLE_ASSIGNMENTS_TO_COLUMN = 419; extern const int CANNOT_UPDATE_COLUMN = 420; extern const int CANNOT_ADD_DIFFERENT_AGGREGATE_STATES = 421; - extern const int UNKNOWN_PROTOCOL = 422; + extern const int UNSUPPORTED_URI_SCHEME = 422; extern const int KEEPER_EXCEPTION = 999; extern const int POCO_EXCEPTION = 1000; diff --git a/dbms/src/IO/HTTPCommon.cpp b/dbms/src/IO/HTTPCommon.cpp index f627a850d68..fb901c4ffaf 100644 --- a/dbms/src/IO/HTTPCommon.cpp +++ b/dbms/src/IO/HTTPCommon.cpp @@ -38,6 +38,7 @@ namespace ErrorCodes extern const int RECEIVED_ERROR_FROM_REMOTE_IO_SERVER; extern const int RECEIVED_ERROR_TOO_MANY_REQUESTS; extern const int FEATURE_IS_NOT_ENABLED_AT_BUILD_TIME; + extern const int UNSUPPORTED_URI_SCHEME; } @@ -52,6 +53,16 @@ namespace #endif } + bool isHTTPS(const Poco::URI & uri) + { + if (uri.getScheme() == "https") + return true; + else if (uri.getScheme() == "http") + return false; + else + throw Exception("Unsupported scheme in URI '" + uri.toString() + "'", ErrorCodes::UNSUPPORTED_URI_SCHEME); + } + HTTPSessionPtr makeHTTPSessionImpl(const std::string & host, UInt16 port, bool https, bool keep_alive) { HTTPSessionPtr session; @@ -127,7 +138,7 @@ namespace std::unique_lock lock(mutex); const std::string & host = uri.getHost(); UInt16 port = uri.getPort(); - bool https = (uri.getScheme() == "https"); + bool https = isHTTPS(uri); auto key = std::make_tuple(host, port, https); auto pool_ptr = endpoints_pool.find(key); if (pool_ptr == endpoints_pool.end()) @@ -157,7 +168,7 @@ HTTPSessionPtr makeHTTPSession(const Poco::URI & uri, const ConnectionTimeouts & { const std::string & host = uri.getHost(); UInt16 port = uri.getPort(); - bool https = (uri.getScheme() == "https"); + bool https = isHTTPS(uri); auto session = makeHTTPSessionImpl(host, port, https, false); setTimeouts(*session, timeouts);