diff options
author | Alex Vakulenko <avakulenko@google.com> | 2016-04-01 18:05:03 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-04-01 18:05:03 +0000 |
commit | 9236a98ccaf60bec65496973b7ef77cd67a6862b (patch) | |
tree | 924e0a97dc86e264c1bee1fa75fe86a43489da93 | |
parent | 88d89453cac2385c1688bbb30dcd00c93bc4defc (diff) | |
parent | 2e4acd4f92c344c1da8cdce042615dac2ab28be5 (diff) | |
download | weaved-9236a98ccaf60bec65496973b7ef77cd67a6862b.tar.gz |
weaved: Implement new libweave\'s methods for WebServer interface am: 3c0af52
am: 2e4acd4
* commit '2e4acd4f92c344c1da8cdce042615dac2ab28be5':
weaved: Implement new libweave's methods for WebServer interface
Change-Id: Ibec4752e2c7f9005be5df154841a751b6e0d9607
-rw-r--r-- | buffet/webserv_client.cc | 26 | ||||
-rw-r--r-- | buffet/webserv_client.h | 5 |
2 files changed, 29 insertions, 2 deletions
diff --git a/buffet/webserv_client.cc b/buffet/webserv_client.cc index 5b35c8b..e6e9c81 100644 --- a/buffet/webserv_client.cc +++ b/buffet/webserv_client.cc @@ -110,17 +110,39 @@ WebServClient::~WebServClient() {} void WebServClient::AddHttpRequestHandler( const std::string& path, const RequestHandlerCallback& callback) { - web_server_->GetDefaultHttpHandler()->AddHandlerCallback( + int handler_id = web_server_->GetDefaultHttpHandler()->AddHandlerCallback( path, "", base::Bind(&WebServClient::OnRequest, weak_ptr_factory_.GetWeakPtr(), callback)); + http_handlers_.emplace(path, handler_id); } void WebServClient::AddHttpsRequestHandler( const std::string& path, const RequestHandlerCallback& callback) { - web_server_->GetDefaultHttpsHandler()->AddHandlerCallback( + int handler_id = web_server_->GetDefaultHttpsHandler()->AddHandlerCallback( path, "", base::Bind(&WebServClient::OnRequest, weak_ptr_factory_.GetWeakPtr(), callback)); + https_handlers_.emplace(path, handler_id); +} + +void WebServClient::RemoveHttpRequestHandler(const std::string& path) { + auto it = http_handlers_.find(path); + if (it == http_handlers_.end()) { + LOG(WARNING) << "No HTTP handler registered for " << path; + return; + } + web_server_->GetDefaultHttpHandler()->RemoveHandler(it->second); + http_handlers_.erase(it); +} + +void WebServClient::RemoveHttpsRequestHandler(const std::string& path) { + auto it = https_handlers_.find(path); + if (it == https_handlers_.end()) { + LOG(WARNING) << "No HTTPS handler registered for " << path; + return; + } + web_server_->GetDefaultHttpsHandler()->RemoveHandler(it->second); + https_handlers_.erase(it); } uint16_t WebServClient::GetHttpPort() const { diff --git a/buffet/webserv_client.h b/buffet/webserv_client.h index 8a12936..18a23c9 100644 --- a/buffet/webserv_client.h +++ b/buffet/webserv_client.h @@ -15,6 +15,7 @@ #ifndef BUFFET_WEBSERV_CLIENT_H_ #define BUFFET_WEBSERV_CLIENT_H_ +#include <map> #include <memory> #include <string> #include <vector> @@ -44,6 +45,8 @@ class WebServClient : public weave::provider::HttpServer { const RequestHandlerCallback& callback) override; void AddHttpsRequestHandler(const std::string& path, const RequestHandlerCallback& callback) override; + void RemoveHttpRequestHandler(const std::string& path) override; + void RemoveHttpsRequestHandler(const std::string& path) override; uint16_t GetHttpPort() const override; uint16_t GetHttpsPort() const override; @@ -64,6 +67,8 @@ class WebServClient : public weave::provider::HttpServer { uint16_t http_port_{0}; uint16_t https_port_{0}; std::vector<uint8_t> certificate_; + std::map<std::string, int> http_handlers_; + std::map<std::string, int> https_handlers_; std::unique_ptr<libwebserv::Server> web_server_; base::Closure server_available_callback_; |