-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHttpClient
More file actions
73 lines (61 loc) · 2.44 KB
/
HttpClient
File metadata and controls
73 lines (61 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* Copyright (C) 2021 Frank Mertens.
*
* Distribution and use is allowed under the terms of the GNU General Public License version 3
* (see CoreComponents/LICENSE-gpl-3.0).
*
*/
#pragma once
#include <cc/Uri>
#include <cc/TlsClientOptions>
#include <cc/SocketAddress>
#include <cc/HttpRequestGenerator>
#include <cc/HttpResponse>
#include <cc/Function>
namespace cc {
/** \class HttpClient cc/HttpClient
* \ingroup http_client
* \brief HTTP client
*/
class HttpClient final: public Object
{
public:
/** Create a new HTTP client (automatically start to establish a connection to \a uri)
* \param uri Provides the host name and port of the HTTP server to connect to
* \param tlsOptions %TLS client credentials and connection parameters
* \note The client will automatically connect to port 443 (TLS) if not explicitly specifying the URI scheme "http".
* \exception HostNameResolutionError
*/
explicit HttpClient(const Uri &uri, const TlsClientOptions &tlsOptions = TlsClientOptions{});
/** Create a new HTTP client (automatically start to establish a connection to \a address)
* \param address The host address and port number of the HTTP server to connect to
* \param tlsOptions %TLS client credentials and connection parameters
*/
explicit HttpClient(const SocketAddress &address, const TlsClientOptions &tlsOptions = TlsClientOptions{});
/** %Address of the HTTP server.
*/
SocketAddress address() const;
/** Wait until the connection to the HTTP server has been established
* \param timeout %Timeout in milliseconds (-1 for indefinite)
* \return True if connection was successfully established before timeout
*/
bool waitEstablished(int timeout = -1);
/** User-defined generator function
*/
using Generate = Function<void(HttpMessageGenerator &)>;
/** Send out HTTP request and wait for the response
* \param method HTTP method ("GET", "HEAD", "PUT", "POST" or "DELETE")
* \param path HTTP request path
* \param generate %Custom method which allows to add custom headers or payload
* \return HTTP response
* \exception IoExhaustion
* \exception HttpCloseRequest
* \exception SystemError
*/
HttpResponse query(const String &method, const String &path = String{}, const Generate &generate = Generate{});
private:
struct State;
State &me();
const State &me() const;
};
} // namespace cc