From 1c4d4c8e5418b6b48a04617e3862870e2e7cf6d0 Mon Sep 17 00:00:00 2001 From: kssenii Date: Sun, 7 Mar 2021 11:31:55 +0000 Subject: [PATCH] Better handlers --- programs/config_tools.h.in | 1 + programs/library-bridge/HandlerFactory.cpp | 6 +----- programs/library-bridge/Handlers.cpp | 11 +++++++++-- programs/library-bridge/Handlers.h | 5 +---- src/Common/Bridge/LibraryBridgeHelper.cpp | 4 ++-- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/programs/config_tools.h.in b/programs/config_tools.h.in index 7cb5a6d883a..abe9ef8c562 100644 --- a/programs/config_tools.h.in +++ b/programs/config_tools.h.in @@ -15,3 +15,4 @@ #cmakedefine01 ENABLE_CLICKHOUSE_GIT_IMPORT #cmakedefine01 ENABLE_CLICKHOUSE_INSTALL #cmakedefine01 ENABLE_CLICKHOUSE_ODBC_BRIDGE +#cmakedefine01 ENABLE_CLICKHOUSE_LIBRARY_BRIDGE diff --git a/programs/library-bridge/HandlerFactory.cpp b/programs/library-bridge/HandlerFactory.cpp index 5b5898cf3d7..f705a3e888c 100644 --- a/programs/library-bridge/HandlerFactory.cpp +++ b/programs/library-bridge/HandlerFactory.cpp @@ -17,11 +17,7 @@ namespace DB return std::make_unique(keep_alive_timeout); if (request.getMethod() == Poco::Net::HTTPRequest::HTTP_POST) - { - /// Remove '/' in the beginning. - auto dictionary_id = uri.getPath().substr(1); - return std::make_unique(keep_alive_timeout, context, dictionary_id); - } + return std::make_unique(keep_alive_timeout, context); return nullptr; } diff --git a/programs/library-bridge/Handlers.cpp b/programs/library-bridge/Handlers.cpp index 9f525a07653..137cbc20d8a 100644 --- a/programs/library-bridge/Handlers.cpp +++ b/programs/library-bridge/Handlers.cpp @@ -53,10 +53,18 @@ void LibraryRequestHandler::handleRequest(HTTPServerRequest & request, HTTPServe return; } + if (!params.has("dictionary_id")) + { + processError(response, "No 'dictionary_id in request URL"); + return; + } + std::string method = params.get("method"); - LOG_TRACE(log, "Library method: '{}'", method); + std::string dictionary_id = params.get("dictionary_id"); + LOG_TRACE(log, "Library method: '{}', dictionary id: {}", method, dictionary_id); WriteBufferFromHTTPServerResponse out(response, request.getMethod() == Poco::Net::HTTPRequest::HTTP_HEAD, keep_alive_timeout); + try { if (method == "libNew") @@ -75,7 +83,6 @@ void LibraryRequestHandler::handleRequest(HTTPServerRequest & request, HTTPServe std::string library_path = params.get("library_path"); std::string library_settings = params.get("library_settings"); - LOG_TRACE(log, "Library path: '{}', library_settings: '{}'", library_path, library_settings); bool res = SharedLibraryHandlerFactory::instance().create(dictionary_id, library_path, library_settings); diff --git a/programs/library-bridge/Handlers.h b/programs/library-bridge/Handlers.h index 2ec66fd598a..b1808751c7c 100644 --- a/programs/library-bridge/Handlers.h +++ b/programs/library-bridge/Handlers.h @@ -17,12 +17,10 @@ public: LibraryRequestHandler( size_t keep_alive_timeout_, - Context & context_, - const std::string & dictionary_id_) + Context & context_) : log(&Poco::Logger::get("LibraryRequestHandler")) , keep_alive_timeout(keep_alive_timeout_) , context(context_) - , dictionary_id(dictionary_id_) { } @@ -34,7 +32,6 @@ private: Poco::Logger * log; size_t keep_alive_timeout; Context & context; - const std::string dictionary_id; }; diff --git a/src/Common/Bridge/LibraryBridgeHelper.cpp b/src/Common/Bridge/LibraryBridgeHelper.cpp index 751c61c7bea..6dd1538dbbd 100644 --- a/src/Common/Bridge/LibraryBridgeHelper.cpp +++ b/src/Common/Bridge/LibraryBridgeHelper.cpp @@ -32,8 +32,8 @@ LibraryBridgeHelper::LibraryBridgeHelper( Poco::URI LibraryBridgeHelper::getDictionaryURI() const { - auto uri = createBaseURI(); - uri.setPath('/' + dictionary_id); + auto uri = getMainURI(); + uri.addQueryParameter("dictionary_id", dictionary_id); return uri; }