diff --git a/include/CSFML/Network/Http.h b/include/CSFML/Network/Http.h index 35852c4..b99a61f 100644 --- a/include/CSFML/Network/Http.h +++ b/include/CSFML/Network/Http.h @@ -29,9 +29,12 @@ //////////////////////////////////////////////////////////// #include +#include #include #include +#include + //////////////////////////////////////////////////////////// /// \brief Enumerate the available HTTP methods for a request @@ -272,12 +275,35 @@ CSFML_NETWORK_API void sfHttp_destroy(const sfHttp* http); /// leave it like this unless you really need a port other /// than the standard one, or use an unknown protocol. /// +/// The host is resolved immediately. To use HTTPS, prefix +/// the host with "https://". +/// /// \param http Http object /// \param host Web server to connect to /// \param port Port to use for connection /// +/// \return True if the host has been resolved and is valid, false otherwise +/// //////////////////////////////////////////////////////////// -CSFML_NETWORK_API void sfHttp_setHost(sfHttp* http, const char* host, unsigned short port); +CSFML_NETWORK_API bool sfHttp_setHost(sfHttp* http, const char* host, unsigned short port); + +//////////////////////////////////////////////////////////// +/// \brief Set the target host of a HTTP object with a given address type +/// +/// See sfHttp_setHost for details. +/// +/// \param http Http object +/// \param host Web server to connect to +/// \param port Port to use for connection +/// \param addressType Address type to use for the connection, NULL to specify no preference +/// +/// \return True if the host has been resolved and is valid, false otherwise +/// +//////////////////////////////////////////////////////////// +CSFML_NETWORK_API bool sfHttp_setHostWithAddressType(sfHttp* http, + const char* host, + unsigned short port, + const sfIpAddressType* addressType); //////////////////////////////////////////////////////////// /// \brief Send a HTTP request and return the server's response. @@ -299,3 +325,23 @@ CSFML_NETWORK_API void sfHttp_setHost(sfHttp* http, const char* host, unsigned s /// //////////////////////////////////////////////////////////// CSFML_NETWORK_API sfHttpResponse* sfHttp_sendRequest(sfHttp* http, const sfHttpRequest* request, sfTime timeout); + +//////////////////////////////////////////////////////////// +/// \brief Send a HTTP request and return the server's response, optionally without verifying the server +/// +/// See sfHttp_sendRequest for details. sfHttp_sendRequest +/// always verifies the server when using HTTPS. +/// +/// \param http Http object +/// \param request Request to send +/// \param timeout Maximum time to wait +/// \param verifyServer Verify the server if using HTTPS +/// +/// \return Server's response +/// +//////////////////////////////////////////////////////////// +CSFML_NETWORK_API sfHttpResponse* sfHttp_sendRequestWithVerification( + const sfHttp* http, + const sfHttpRequest* request, + sfTime timeout, + bool verifyServer); diff --git a/src/CSFML/Network/Http.cpp b/src/CSFML/Network/Http.cpp index ea5877a..2586c2f 100644 --- a/src/CSFML/Network/Http.cpp +++ b/src/CSFML/Network/Http.cpp @@ -25,6 +25,7 @@ //////////////////////////////////////////////////////////// // Headers //////////////////////////////////////////////////////////// +#include #include #include @@ -149,10 +150,18 @@ void sfHttp_destroy(const sfHttp* http) //////////////////////////////////////////////////////////// -void sfHttp_setHost(sfHttp* http, const char* host, unsigned short port) +bool sfHttp_setHost(sfHttp* http, const char* host, unsigned short port) { assert(http); - http->setHost(host ? host : "", port); + return http->setHost(host ? host : "", port); +} + + +//////////////////////////////////////////////////////////// +bool sfHttp_setHostWithAddressType(sfHttp* http, const char* host, unsigned short port, const sfIpAddressType* addressType) +{ + assert(http); + return http->setHost(host ? host : "", port, convertIpAddressType(addressType)); } @@ -163,3 +172,12 @@ sfHttpResponse* sfHttp_sendRequest(sfHttp* http, const sfHttpRequest* request, s assert(request); return new sfHttpResponse{http->sendRequest(*request, sf::microseconds(timeout.microseconds))}; } + + +//////////////////////////////////////////////////////////// +sfHttpResponse* sfHttp_sendRequestWithVerification(const sfHttp* http, const sfHttpRequest* request, sfTime timeout, bool verifyServer) +{ + assert(http); + assert(request); + return new sfHttpResponse{http->sendRequest(*request, sf::microseconds(timeout.microseconds), verifyServer)}; +}