diff --git a/include/opendht/dht_proxy_client.h b/include/opendht/dht_proxy_client.h index 905517724caad9f50af83f0f75c645de589df6cc..f9259890bdb8ded279dbd719cb69473a2ca6cb70 100644 --- a/include/opendht/dht_proxy_client.h +++ b/include/opendht/dht_proxy_client.h @@ -27,23 +27,22 @@ #include "def.h" #include "dht_interface.h" #include "proxy.h" +#include "http.h" #include <restinio/all.hpp> -#include <http_parser.h> #include <json/json.h> -#include "http.h" #include <chrono> #include <vector> #include <functional> namespace Json { - class Value; +class Value; } namespace http { - class Resolver; - class Request; +class Resolver; +class Request; } namespace dht { diff --git a/include/opendht/dht_proxy_server.h b/include/opendht/dht_proxy_server.h index 4d8d00b665b84cf027647436fdcbc3e5f66a8fc3..da50bdea0f2f0f9340966176ee34fd1ba7d4efcb 100644 --- a/include/opendht/dht_proxy_server.h +++ b/include/opendht/dht_proxy_server.h @@ -27,33 +27,30 @@ #include "scheduler.h" #include "sockaddr.h" #include "value.h" -#include "dht_proxy_client.h" - -#include <memory> -#include <mutex> +#include "http.h" #include <restinio/all.hpp> #include <restinio/tls.hpp> -#include "http.h" #ifdef OPENDHT_JSONCPP #include <json/json.h> #endif +#include <memory> +#include <mutex> + namespace http { - class Request; - class opendht_logger_t; - struct ListenerSession; - class ConnectionListener; +class Request; +struct ListenerSession; +class ConnectionListener; } namespace restinio { - class opendht_logger_t; - struct custom_http_methods_t; +class opendht_logger_t; } namespace Json { - class Value; +class Value; } namespace dht { diff --git a/include/opendht/http.h b/include/opendht/http.h index 975463f2a474f7f0799a05e3a3714cd87c3d00b6..0b23f62b3a5d7491ce80148c373a5cd63a84a711 100644 --- a/include/opendht/http.h +++ b/include/opendht/http.h @@ -18,15 +18,20 @@ #pragma once +#include "def.h" +#include "log.h" + #include <asio.hpp> -#include "asio/ssl.hpp" +#include <asio/ssl.hpp> + #include <json/json.h> -#include <http_parser.h> #include <restinio/all.hpp> #include <restinio/impl/tls_socket.hpp> -#include <opendht.h> -#include <opendht/def.h> -#include <opendht/log.h> + +extern "C" { +struct http_parser; +struct http_parser_settings; +} namespace http { @@ -341,25 +346,10 @@ private: /* Custom HTTP-methods for RESTinio > 0.5.0. * https://github.com/Stiffstream/restinio/issues/26 */ -constexpr const restinio::http_method_id_t method_listen{HTTP_LISTEN, "LISTEN"}; -constexpr const restinio::http_method_id_t method_stats{HTTP_STATS, "STATS"}; -constexpr const restinio::http_method_id_t method_sign{HTTP_SIGN, "SIGN"}; -constexpr const restinio::http_method_id_t method_encrypt{HTTP_ENCRYPT, "ENCRYPT"}; - -struct custom_http_methods_t -{ - static constexpr restinio::http_method_id_t from_nodejs(int m) noexcept { - if(m == method_listen.raw_id()) - return method_listen; - else if(m == method_stats.raw_id()) - return method_stats; - else if(m == method_sign.raw_id()) - return method_sign; - else if(m == method_encrypt.raw_id()) - return method_encrypt; - else - return restinio::default_http_methods_t::from_nodejs(m); - } -}; +constexpr const restinio::http_method_id_t method_listen {HTTP_LISTEN, "LISTEN"}; +constexpr const restinio::http_method_id_t method_stats {HTTP_STATS, "STATS"}; +constexpr const restinio::http_method_id_t method_sign {HTTP_SIGN, "SIGN"}; +constexpr const restinio::http_method_id_t method_encrypt {HTTP_ENCRYPT, "ENCRYPT"}; #endif + } // namespace restinio diff --git a/src/dht_proxy_client.cpp b/src/dht_proxy_client.cpp index f307cf2c71a208f0f6f16d375fe1dbb4cf8365f0..25c3b919985a0954483d928c2276006b127f454f 100644 --- a/src/dht_proxy_client.cpp +++ b/src/dht_proxy_client.cpp @@ -23,6 +23,8 @@ #include "op_cache.h" #include "utils.h" +#include <http_parser.h> + namespace dht { struct DhtProxyClient::InfoState { @@ -826,7 +828,7 @@ DhtProxyClient::listen(const InfoHash& key, ValueCallback cb, Value::Filter filt if (deviceKey_.empty()){ // listen method = ListenMethod::LISTEN; #ifdef OPENDHT_PROXY_HTTP_PARSER_FORK - header.method(restinio::custom_http_methods_t::from_nodejs(restinio::method_listen.raw_id())); + header.method(restinio::method_listen); header.request_target("/" + key.toString()); #else header.method(restinio::http_method_get()); @@ -1155,7 +1157,7 @@ DhtProxyClient::restartListeners() // define header restinio::http_request_header_t header; #ifdef OPENDHT_PROXY_HTTP_PARSER_FORK - header.method(restinio::custom_http_methods_t::from_nodejs(restinio::method_listen.raw_id())); + header.method(restinio::method_listen); header.request_target("/" + search.first.toString()); #else header.method(restinio::http_method_get()); diff --git a/src/dht_proxy_server.cpp b/src/dht_proxy_server.cpp index 0a4cc687fb2799d85d384bd1056f9bac205a1628..f42fdd2e84a33e536bd3d0bf7f6a494de9b71cb7 100644 --- a/src/dht_proxy_server.cpp +++ b/src/dht_proxy_server.cpp @@ -33,6 +33,26 @@ using namespace std::placeholders; +#ifdef OPENDHT_PROXY_HTTP_PARSER_FORK +namespace restinio { +struct custom_http_methods_t +{ + static constexpr restinio::http_method_id_t from_nodejs(int m) noexcept { + if(m == method_listen.raw_id()) + return method_listen; + else if(m == method_stats.raw_id()) + return method_stats; + else if(m == method_sign.raw_id()) + return method_sign; + else if(m == method_encrypt.raw_id()) + return method_encrypt; + else + return restinio::default_http_methods_t::from_nodejs(m); + } +}; +} +#endif + namespace dht { constexpr char RESP_MSG_DESTINATION_NOT_FOUND[] = "{\"err\":\"No destination found\"}"; diff --git a/src/http.cpp b/src/http.cpp index a4266ea855c2760485bc262f5f61ceedaa732908..7ed02a62587e7fee9f5bdd3dcaaeabb980871a67 100644 --- a/src/http.cpp +++ b/src/http.cpp @@ -18,6 +18,8 @@ #include "http.h" +#include <http_parser.h> + namespace http { constexpr char HTTP_HEADER_CONNECTION[] = "Connection";