Ark Server API (ASE) - Wiki
Loading...
Searching...
No Matches
HTTPSClientSession.h
Go to the documentation of this file.
1//
2// HTTPSClientSession.h
3//
4// Library: NetSSL_OpenSSL
5// Package: HTTPSClient
6// Module: HTTPSClientSession
7//
8// Definition of the HTTPSClientSession class.
9//
10// Copyright (c) 2006-2009, Applied Informatics Software Engineering GmbH.
11// and Contributors.
12//
13// SPDX-License-Identifier: BSL-1.0
14//
15
16
17#ifndef NetSSL_HTTPSClientSession_INCLUDED
18#define NetSSL_HTTPSClientSession_INCLUDED
19
20
21#include "Poco/Net/NetSSL.h"
22#include "Poco/Net/Utility.h"
23#include "Poco/Net/HTTPClientSession.h"
24#include "Poco/Net/Context.h"
25#include "Poco/Net/Session.h"
26#include "Poco/Net/X509Certificate.h"
27
28
29namespace Poco {
30namespace Net {
31
32
33class SecureStreamSocket;
34class HTTPRequest;
35class HTTPResponse;
36
37
39 /// This class implements the client-side of
40 /// a HTTPS session.
41 ///
42 /// To send a HTTPS request to a HTTPS server, first
43 /// instantiate a HTTPSClientSession object and
44 /// specify the server's host name and port number.
45 ///
46 /// Then create a HTTPRequest object, fill it accordingly,
47 /// and pass it as argument to the sendRequest() method.
48 ///
49 /// sendRequest() will return an output stream that can
50 /// be used to send the request body, if there is any.
51 ///
52 /// After you are done sending the request body, create
53 /// a HTTPResponse object and pass it to receiveResponse().
54 ///
55 /// This will return an input stream that can be used to
56 /// read the response body.
57 ///
58 /// See RFC 2616 <http://www.faqs.org/rfcs/rfc2616.html> for more
59 /// information about the HTTP protocol.
60 ///
61 /// Note that sending requests that neither contain a content length
62 /// field in the header nor are using chunked transfer encoding will
63 /// result in a SSL protocol violation, as the framework shuts down
64 /// the socket after sending the message body. No orderly SSL shutdown
65 /// will be performed in this case.
66 ///
67 /// If session caching has been enabled for the Context object passed
68 /// to the HTTPSClientSession, the HTTPSClientSession class will
69 /// attempt to reuse a previously obtained Session object in
70 /// case of a reconnect.
71{
72public:
73 enum
74 {
75 HTTPS_PORT = 443
76 };
77
79 /// Creates an unconnected HTTPSClientSession.
80
81 explicit HTTPSClientSession(const SecureStreamSocket& socket);
82 /// Creates a HTTPSClientSession using the given socket.
83 /// The socket must not be connected. The session
84 /// takes ownership of the socket.
85
86 HTTPSClientSession(const SecureStreamSocket& socket, Session::Ptr pSession);
87 /// Creates a HTTPSClientSession using the given socket.
88 /// The socket must not be connected. The session
89 /// takes ownership of the socket.
90 ///
91 /// The given Session is reused, if possible (client session
92 /// caching is enabled for the given Context, and the server
93 /// agrees to reuse the session).
94
95 HTTPSClientSession(const std::string& host, Poco::UInt16 port = HTTPS_PORT);
96 /// Creates a HTTPSClientSession using the given host and port.
97
98 explicit HTTPSClientSession(Context::Ptr pContext);
99 /// Creates an unconnected HTTPSClientSession, using the
100 /// give SSL context.
101
102 HTTPSClientSession(Context::Ptr pContext, Session::Ptr pSession);
103 /// Creates an unconnected HTTPSClientSession, using the
104 /// give SSL context.
105 ///
106 /// The given Session is reused, if possible (client session
107 /// caching is enabled for the given Context, and the server
108 /// agrees to reuse the session).
109
110 HTTPSClientSession(const std::string& host, Poco::UInt16 port, Context::Ptr pContext);
111 /// Creates a HTTPSClientSession using the given host and port,
112 /// using the given SSL context.
113
114 HTTPSClientSession(const std::string& host, Poco::UInt16 port, Context::Ptr pContext, Session::Ptr pSession);
115 /// Creates a HTTPSClientSession using the given host and port,
116 /// using the given SSL context.
117 ///
118 /// The given Session is reused, if possible (client session
119 /// caching is enabled for the given Context, and the server
120 /// agrees to reuse the session).
121
123 /// Destroys the HTTPSClientSession and closes
124 /// the underlying socket.
125
126 bool secure() const;
127 /// Return true iff the session uses SSL or TLS,
128 /// or false otherwise.
129
131 /// Returns the server's certificate.
132 ///
133 /// The certificate is available after the first request has been sent.
134
136 /// Returns the SSL Session object for the current
137 /// connection, if session caching has been enabled for
138 /// the HTTPSClientSession's Context. A null pointer is
139 /// returned otherwise.
140 ///
141 /// The Session object can be obtained after the first request has
142 /// been sent.
143
144 // HTTPSession
145 void abort();
146
147protected:
148 void connect(const SocketAddress& address);
149 std::string proxyRequestPrefix() const;
151 int read(char* buffer, std::streamsize length);
152
153private:
156
159};
160
161
162} } // namespace Poco::Net
163
164
165#endif // Net_HTTPSClientSession_INCLUDED
#define ARK_API
Definition Base.h:9
#define NetSSL_API
Definition NetSSL.h:48
virtual std::unique_ptr< ArkApi::ICommands > & GetCommands()=0
std::mutex RequestMutex_
Definition Requests.cpp:47
void WriteRequest(std::function< void(bool, std::string)> callback, bool success, std::string result)
Definition Requests.cpp:73
std::string GetResponse(Poco::Net::HTTPClientSession *session, Poco::Net::HTTPResponse &response)
Definition Requests.cpp:107
Poco::Net::HTTPRequest ConstructRequest(const std::string &url, Poco::Net::HTTPClientSession *&session, const std::vector< std::string > &headers, const std::string &request_type)
Definition Requests.cpp:79
std::vector< RequestData > RequestsVec_
Definition Requests.cpp:46
Requests(Requests &&)=delete
ARK_API bool CreateGetRequest(const std::string &url, const std::function< void(bool, std::string)> &callback, std::vector< std::string > headers={})
Creates an async GET Request that runs in another thread but calls the callback from the main thread.
Definition Requests.cpp:129
ARK_API bool CreatePostRequest(const std::string &url, const std::function< void(bool, std::string)> &callback, const std::vector< std::string > &post_ids, const std::vector< std::string > &post_data, std::vector< std::string > headers={})
Creates an async POST Request that runs in another thread but calls the callback from the main thread...
Definition Requests.cpp:238
Requests & operator=(Requests &&)=delete
ARK_API bool CreateDeleteRequest(const std::string &url, const std::function< void(bool, std::string)> &callback, std::vector< std::string > headers={})
Creates an async DELETE Request that runs in another thread but calls the callback from the main thre...
Definition Requests.cpp:292
Requests & operator=(const Requests &)=delete
ARK_API bool CreatePostRequest(const std::string &url, const std::function< void(bool, std::string)> &callback, const std::string &post_data, std::vector< std::string > headers={})
Creates an async POST Request with application/x-www-form-urlencoded content type that runs in anothe...
Definition Requests.cpp:162
static ARK_API Requests & Get()
Definition Requests.cpp:67
ARK_API bool CreatePostRequest(const std::string &url, const std::function< void(bool, std::string)> &callback, const std::string &post_data, const std::string &content_type, std::vector< std::string > headers={})
Creates an async POST Request that runs in another thread but calls the callback from the main thread...
Definition Requests.cpp:200
std::unique_ptr< impl > pimpl
Definition Requests.h:84
Requests(const Requests &)=delete
virtual void AddOnTickCallback(const FString &id, const std::function< void(float)> &callback)=0
Added function will be called every frame.
virtual bool RemoveOnTickCallback(const FString &id)=0
Removes a on-tick callback.
Definition Logger.h:9
static std::shared_ptr< spdlog::logger > & GetLog()
Definition Logger.h:22
std::string displayText() const
Returns the exception code if defined.
virtual std::istream & receiveResponse(HTTPResponse &response)
virtual std::ostream & sendRequest(HTTPRequest &request)
Returns the connection timeout for HTTP connections.
static const std::string HTTP_1_1
void setContentLength(std::streamsize length)
Returns the HTTP version for this message.
HTTPRequest(const std::string &method, const std::string &uri, const std::string &version)
Creates a HTTP/1.0 request with the given method and URI.
static const std::string HTTP_GET
static const std::string HTTP_DELETE
static const std::string HTTP_POST
const std::string & getReason() const
Sets the HTTP reason phrase.
HTTPResponse(HTTPStatus status)
HTTPStatus getStatus() const
HTTPSClientSession(const std::string &host, Poco::UInt16 port, Context::Ptr pContext, Session::Ptr pSession)
std::string proxyRequestPrefix() const
Sends the given HTTPRequest over an existing connection.
HTTPSClientSession(Context::Ptr pContext, Session::Ptr pSession)
HTTPSClientSession(Context::Ptr pContext)
Creates a HTTPSClientSession using the given host and port.
void proxyAuthenticate(HTTPRequest &request)
Checks if we can reuse a persistent connection.
int read(char *buffer, std::streamsize length)
HTTPSClientSession(const HTTPSClientSession &)
void connect(const SocketAddress &address)
Refills the internal buffer.
HTTPSClientSession(const SecureStreamSocket &socket, Session::Ptr pSession)
X509Certificate serverCertificate()
HTTPSClientSession & operator=(const HTTPSClientSession &)
HTTPSClientSession(const std::string &host, Poco::UInt16 port=HTTPS_PORT)
HTTPSClientSession(const SecureStreamSocket &socket)
Creates an unconnected HTTPSClientSession.
HTTPSClientSession(const std::string &host, Poco::UInt16 port, Context::Ptr pContext)
RejectCertificateHandler(bool handleErrorsOnServerSide)
void initializeClient(PrivateKeyPassphraseHandlerPtr ptrPassphraseHandler, InvalidCertificateHandlerPtr ptrHandler, Context::Ptr ptrContext)
static SSLManager & instance()
This stream discards all characters written to it.
Definition NullStream.h:77
static std::streamsize copyStream(std::istream &istr, std::ostream &ostr, std::size_t bufferSize=8192)
const std::string & getHost() const
Sets the user-info part of the URI.
Definition URI.h:385
const std::string & getScheme() const
Definition URI.h:373
URI(const std::string &uri)
Creates an empty URI.
unsigned short getPort() const
Sets the host part of the URI.
std::string getPathAndQuery() const
Returns the encoded path, query and fragment parts of the URI.
void error(const T &)
Definition IBaseApi.h:9
std::unique_ptr< IBaseApi > game_api
Definition IBaseApi.h:25
void NetSSL_API initializeSSL()
void NetSSL_API uninitializeSSL()
Definition format.h:408
Definition json.hpp:4518
std::function< void(bool, std::string)> callback
Definition Requests.cpp:41
static std::string escape(const std::string &s, bool strictJSON=false)