Deprecated Request::remote_endpoint_address() and Request::remote_endpoint_port()

This commit is contained in:
eidheim 2019-09-17 10:52:40 +02:00
commit a1d8282918
5 changed files with 20 additions and 8 deletions

View file

@ -89,7 +89,7 @@ int main() {
// Responds with request-information // Responds with request-information
server.resource["^/info$"]["GET"] = [](shared_ptr<HttpServer::Response> response, shared_ptr<HttpServer::Request> request) { server.resource["^/info$"]["GET"] = [](shared_ptr<HttpServer::Response> response, shared_ptr<HttpServer::Request> request) {
stringstream stream; stringstream stream;
stream << "<h1>Request from " << request->remote_endpoint_address() << ":" << request->remote_endpoint_port() << "</h1>"; stream << "<h1>Request from " << request->remote_endpoint().address().to_string() << ":" << request->remote_endpoint().port() << "</h1>";
stream << request->method << " " << request->path << " HTTP/" << request->http_version; stream << request->method << " " << request->path << " HTTP/" << request->http_version;

View file

@ -87,7 +87,7 @@ int main() {
// Responds with request-information // Responds with request-information
server.resource["^/info$"]["GET"] = [](shared_ptr<HttpsServer::Response> response, shared_ptr<HttpsServer::Request> request) { server.resource["^/info$"]["GET"] = [](shared_ptr<HttpsServer::Response> response, shared_ptr<HttpsServer::Request> request) {
stringstream stream; stringstream stream;
stream << "<h1>Request from " << request->remote_endpoint_address() << ":" << request->remote_endpoint_port() << "</h1>"; stream << "<h1>Request from " << request->remote_endpoint().address().to_string() << ":" << request->remote_endpoint().port() << "</h1>";
stream << request->method << " " << request->path << " HTTP/" << request->http_version; stream << request->method << " " << request->path << " HTTP/" << request->http_version;

View file

@ -254,7 +254,8 @@ namespace SimpleWeb {
return asio::ip::tcp::endpoint(); return asio::ip::tcp::endpoint();
} }
std::string remote_endpoint_address() const noexcept { /// Deprecated, please use remote_endpoint().address().to_string() instead.
DEPRECATED std::string remote_endpoint_address() const noexcept {
try { try {
if(auto connection = this->connection.lock()) if(auto connection = this->connection.lock())
return connection->socket->lowest_layer().remote_endpoint().address().to_string(); return connection->socket->lowest_layer().remote_endpoint().address().to_string();
@ -264,7 +265,8 @@ namespace SimpleWeb {
return std::string(); return std::string();
} }
unsigned short remote_endpoint_port() const noexcept { /// Deprecated, please use remote_endpoint().port() instead.
DEPRECATED unsigned short remote_endpoint_port() const noexcept {
try { try {
if(auto connection = this->connection.lock()) if(auto connection = this->connection.lock())
return connection->socket->lowest_layer().remote_endpoint().port(); return connection->socket->lowest_layer().remote_endpoint().port();

View file

@ -61,8 +61,8 @@ int main() {
*response << "HTTP/1.1 200 OK\r\nContent-Length: " << content.length() << "\r\n\r\n" *response << "HTTP/1.1 200 OK\r\nContent-Length: " << content.length() << "\r\n\r\n"
<< content; << content;
ASSERT(!request->remote_endpoint_address().empty()); ASSERT(!request->remote_endpoint().address().to_string().empty());
ASSERT(request->remote_endpoint_port() != 0); ASSERT(request->remote_endpoint().port() != 0);
}; };
server.resource["^/string/dup$"]["POST"] = [](shared_ptr<HttpServer::Response> response, shared_ptr<HttpServer::Request> request) { server.resource["^/string/dup$"]["POST"] = [](shared_ptr<HttpServer::Response> response, shared_ptr<HttpServer::Request> request) {
@ -75,8 +75,8 @@ int main() {
*response << content; *response << content;
response->send(); response->send();
ASSERT(!request->remote_endpoint_address().empty()); ASSERT(!request->remote_endpoint().address().to_string().empty());
ASSERT(request->remote_endpoint_port() != 0); ASSERT(request->remote_endpoint().port() != 0);
}; };
server.resource["^/string2$"]["POST"] = [](shared_ptr<HttpServer::Response> response, shared_ptr<HttpServer::Request> request) { server.resource["^/string2$"]["POST"] = [](shared_ptr<HttpServer::Response> response, shared_ptr<HttpServer::Request> request) {

View file

@ -12,6 +12,16 @@
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#ifndef DEPRECATED
#if defined(__GNUC__) || defined(__clang__)
#define DEPRECATED __attribute__((deprecated))
#elif defined(_MSC_VER)
#define DEPRECATED __declspec(deprecated)
#else
#define DEPRECATED
#endif
#endif
#if __cplusplus > 201402L || _MSVC_LANG > 201402L #if __cplusplus > 201402L || _MSVC_LANG > 201402L
#include <string_view> #include <string_view>
namespace SimpleWeb { namespace SimpleWeb {