From 3290da6b647a194c65b4f12fad4bcfcebdeab6d5 Mon Sep 17 00:00:00 2001 From: Joaquim Vila <36737101+joaquimvila@users.noreply.github.com> Date: Wed, 15 Jan 2020 23:41:57 +0100 Subject: [PATCH] =?UTF-8?q?Removed=20unused=20help=C3=A8rs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Helpers/HttpClient.cpp | 100 ------------------ .../Helpers/HttpClient.h | 29 ----- .../Helpers/HttpsClient.cpp | 76 ------------- .../Helpers/HttpsClient.h | 18 ---- 4 files changed, 223 deletions(-) delete mode 100644 test/HttpLibWebServerAdapterTest/Helpers/HttpClient.cpp delete mode 100644 test/HttpLibWebServerAdapterTest/Helpers/HttpClient.h delete mode 100644 test/HttpLibWebServerAdapterTest/Helpers/HttpsClient.cpp delete mode 100644 test/HttpLibWebServerAdapterTest/Helpers/HttpsClient.h diff --git a/test/HttpLibWebServerAdapterTest/Helpers/HttpClient.cpp b/test/HttpLibWebServerAdapterTest/Helpers/HttpClient.cpp deleted file mode 100644 index f9151a1..0000000 --- a/test/HttpLibWebServerAdapterTest/Helpers/HttpClient.cpp +++ /dev/null @@ -1,100 +0,0 @@ -#include "stdafx.h" -#include "HttpClient.h" - -#include "WebServerAdapterInterface/Model/Reply.h" -#include "WebServerAdapterInterface/Model/Request.h" - -#include -#include - - -namespace systelab { namespace web_server { namespace httplib { namespace test { - - HttpClient::HttpClient() = default; - HttpClient::~HttpClient() = default; - - std::unique_ptr HttpClient::send(const std::string& serverAddress, unsigned int port, const Request& request) const - { - ::httplib::Client client(serverAddress, port); - client.set_timeout_sec(600); - client.set_read_timeout(600, 1); - - ::httplib::Headers httpLibHeaders; - for (auto& header : request.getHeaders().getHeadersMap()) - { - if (header.first != "Content-Type") - { - httpLibHeaders.emplace(header.first.c_str(), header.second.c_str()); - } - } - - std::shared_ptr<::httplib::Response> httpLibResponse; - if (request.getMethod() == "GET") - { - httpLibResponse = client.Get(request.getURI().c_str(), httpLibHeaders); - } - else if (request.getMethod() == "POST") - { - std::string contentType = request.getHeaders().hasHeader("Content-Type") ? request.getHeaders().getHeader("Content-Type") : "text/plain"; - httpLibResponse = client.Post(request.getURI().c_str(), httpLibHeaders, request.getContent(), contentType.c_str()); - } - else if (request.getMethod() == "PUT") - { - std::string contentType = request.getHeaders().hasHeader("Content-Type") ? request.getHeaders().getHeader("Content-Type") : "text/plain"; - httpLibResponse = client.Put(request.getURI().c_str(), httpLibHeaders, request.getContent(), contentType.c_str()); - } - else if (request.getMethod() == "PATCH") - { - std::string contentType = request.getHeaders().hasHeader("Content-Type") ? request.getHeaders().getHeader("Content-Type") : "text/plain"; - httpLibResponse = client.Patch(request.getURI().c_str(), httpLibHeaders, request.getContent(), contentType.c_str()); - } - else if (request.getMethod() == "DELETE") - { - std::string contentType = request.getHeaders().hasHeader("Content-Type") ? request.getHeaders().getHeader("Content-Type") : "text/plain"; - httpLibResponse = client.Delete(request.getURI().c_str(), httpLibHeaders, request.getContent(), contentType.c_str()); - } - else if (request.getMethod() == "OPTIONS") - { - std::string contentType = request.getHeaders().hasHeader("Content-Type") ? request.getHeaders().getHeader("Content-Type") : "text/plain"; - httpLibResponse = client.Options(request.getURI().c_str(), httpLibHeaders); - } - else - { - throw std::runtime_error("Unsupported method"); - } - - if (!httpLibResponse) - { - return nullptr; - } - - return buildReply(*httpLibResponse); - } - - void HttpClient::fillHttplibRequest(const Request& request, ::httplib::Request& httplibRequest) const - { - httplibRequest.method = request.getMethod(); - httplibRequest.path = request.getURI(); - httplibRequest.body = request.getContent(); - - for (auto& header : request.getHeaders().getHeadersMap()) - { - httplibRequest.set_header(header.first.c_str(), header.second.c_str()); - } - } - - std::unique_ptr HttpClient::buildReply(::httplib::Response httplibResponse) const - { - auto reply = std::make_unique(); - reply->setStatus(static_cast(httplibResponse.status)); - reply->setContent(httplibResponse.body); - - for (auto& header : httplibResponse.headers) - { - reply->addHeader(header.first, header.second); - } - - return reply; - } - -}}}} diff --git a/test/HttpLibWebServerAdapterTest/Helpers/HttpClient.h b/test/HttpLibWebServerAdapterTest/Helpers/HttpClient.h deleted file mode 100644 index 8c3bf69..0000000 --- a/test/HttpLibWebServerAdapterTest/Helpers/HttpClient.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -namespace httplib { - struct Request; - struct Response; -} - -namespace systelab { namespace web_server { - class Reply; - class Request; -}} - -namespace systelab { namespace web_server { namespace httplib { namespace test { - - class HttpClient - { - public: - HttpClient(); - virtual ~HttpClient(); - - virtual std::unique_ptr send(const std::string& serverAddress, unsigned int port, const Request&) const; - - protected: - void fillHttplibRequest(const Request&, ::httplib::Request&) const; - std::unique_ptr buildReply(::httplib::Response) const; - }; - -}}}} - diff --git a/test/HttpLibWebServerAdapterTest/Helpers/HttpsClient.cpp b/test/HttpLibWebServerAdapterTest/Helpers/HttpsClient.cpp deleted file mode 100644 index 3f9cff8..0000000 --- a/test/HttpLibWebServerAdapterTest/Helpers/HttpsClient.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include "stdafx.h" -#include "HttpsClient.h" - -#include "WebServerAdapterInterface/Model/Reply.h" -#include "WebServerAdapterInterface/Model/Request.h" - -#include -#include - - -namespace systelab { namespace web_server { namespace httplib { namespace test { - - HttpsClient::HttpsClient() = default; - HttpsClient::~HttpsClient() = default; - - std::unique_ptr HttpsClient::send(const std::string& serverAddress, - unsigned int port, - const Request& request) const - { - ::httplib::SSLClient client(serverAddress, port); - client.set_timeout_sec(600); - client.set_read_timeout(600, 1); - - ::httplib::Headers httpLibHeaders; - for (auto& header : request.getHeaders().getHeadersMap()) - { - if (header.first != "Content-Type") - { - httpLibHeaders.emplace(header.first.c_str(), header.second.c_str()); - } - } - - std::shared_ptr<::httplib::Response> httpLibResponse; - if (request.getMethod() == "GET") - { - httpLibResponse = client.Get(request.getURI().c_str(), httpLibHeaders); - } - else if (request.getMethod() == "POST") - { - std::string contentType = request.getHeaders().hasHeader("Content-Type") ? request.getHeaders().getHeader("Content-Type") : "text/plain"; - httpLibResponse = client.Post(request.getURI().c_str(), httpLibHeaders, request.getContent(), contentType.c_str()); - } - else if (request.getMethod() == "PUT") - { - std::string contentType = request.getHeaders().hasHeader("Content-Type") ? request.getHeaders().getHeader("Content-Type") : "text/plain"; - httpLibResponse = client.Put(request.getURI().c_str(), httpLibHeaders, request.getContent(), contentType.c_str()); - } - else if (request.getMethod() == "PATCH") - { - std::string contentType = request.getHeaders().hasHeader("Content-Type") ? request.getHeaders().getHeader("Content-Type") : "text/plain"; - httpLibResponse = client.Patch(request.getURI().c_str(), httpLibHeaders, request.getContent(), contentType.c_str()); - } - else if (request.getMethod() == "DELETE") - { - std::string contentType = request.getHeaders().hasHeader("Content-Type") ? request.getHeaders().getHeader("Content-Type") : "text/plain"; - httpLibResponse = client.Delete(request.getURI().c_str(), httpLibHeaders, request.getContent(), contentType.c_str()); - } - else if (request.getMethod() == "OPTIONS") - { - std::string contentType = request.getHeaders().hasHeader("Content-Type") ? request.getHeaders().getHeader("Content-Type") : "text/plain"; - httpLibResponse = client.Options(request.getURI().c_str(), httpLibHeaders); - } - else - { - throw std::runtime_error("Unsupported method"); - } - - if (!httpLibResponse) - { - return nullptr; - } - - return buildReply(*httpLibResponse); - } - -}}}} diff --git a/test/HttpLibWebServerAdapterTest/Helpers/HttpsClient.h b/test/HttpLibWebServerAdapterTest/Helpers/HttpsClient.h deleted file mode 100644 index 481eed9..0000000 --- a/test/HttpLibWebServerAdapterTest/Helpers/HttpsClient.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "HttpClient.h" - - -namespace systelab { namespace web_server { namespace httplib { namespace test { - - class HttpsClient : public HttpClient - { - public: - HttpsClient(); - virtual ~HttpsClient(); - - std::unique_ptr send(const std::string& serverAddress, unsigned int port, const Request&) const; - }; - -}}}} -