Skip to content

Commit

Permalink
Simplify method implementation
Browse files Browse the repository at this point in the history
There is no need to create enum class for enum types.
We will manage directly the method as std::string
because 3rd party does the same.

We will save time in conversions and reduce source code.

Jira:
  • Loading branch information
Eduardo Ramos Testillano (eramedu) committed Apr 30, 2023
1 parent c458842 commit c7aed6c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
9 changes: 2 additions & 7 deletions include/ert/http2comm/Http2Client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ class Http2Client
//inner classes
public:

enum class Method
{
POST, GET, PUT, DELETE, HEAD
};

struct response
{
std::string body;
Expand Down Expand Up @@ -127,15 +122,15 @@ class Http2Client
/**
* Send request to the server
*
* @param method Request method
* @param method Request method (POST, GET, PUT, DELETE, HEAD)
* @param path Request uri path including optional query parameters
* @param body Request body
* @param headers Request headers
* @param requestTimeout Request timeout, 1 second by default
*
* @return Response structure. Status code -1 means connection error, and -2 means timeout.
*/
Http2Client::response send(const Http2Client::Method &method,
Http2Client::response send(const std::string &method,
const std::string &path,
const std::string &body,
const nghttp2::asio_http2::header_map &headers,
Expand Down
17 changes: 3 additions & 14 deletions src/Http2Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,6 @@ SOFTWARE.
#include <ert/http2comm/Http2Headers.hpp>
#include <ert/http2comm/Http2Client.hpp>

namespace
{
std::map<ert::http2comm::Http2Client::Method, std::string> method_to_str = {
{ ert::http2comm::Http2Client::Method::POST, "POST" },
{ ert::http2comm::Http2Client::Method::GET, "GET" },
{ ert::http2comm::Http2Client::Method::PUT, "PUT" },
{ ert::http2comm::Http2Client::Method::DELETE, "DELETE" },
{ ert::http2comm::Http2Client::Method::HEAD, "HEAD" }
};
}

namespace ert
{
Expand Down Expand Up @@ -96,7 +86,7 @@ void Http2Client::reconnect()
}

Http2Client::response Http2Client::send(
const Http2Client::Method &method,
const std::string &method,
const std::string &path,
const std::string &body,
const nghttp2::asio_http2::header_map &headers,
Expand All @@ -114,18 +104,17 @@ Http2Client::response Http2Client::send(
}

auto url = getUri(path);
auto method_str = ::method_to_str[method];

LOGINFORMATIONAL(
ert::tracing::Logger::informational(ert::tracing::Logger::asString("Sending %s request to url: %s; body: %s; headers: %s; %s",
method_str.c_str(), url.c_str(), body.c_str(), headersAsString(headers).c_str(), connection_->asString().c_str()), ERT_FILE_LOCATION);
method.c_str(), url.c_str(), body.c_str(), headersAsString(headers).c_str(), connection_->asString().c_str()), ERT_FILE_LOCATION);
);

auto submit = [&, url](const nghttp2::asio_http2::client::session & sess,
const nghttp2::asio_http2::header_map & headers, boost::system::error_code & ec)
{

return sess.submit(ec, method_str, url, body, headers);
return sess.submit(ec, method, url, body, headers);
};

const auto& session = connection_->getSession();
Expand Down

0 comments on commit c7aed6c

Please sign in to comment.