HttpClient.h
1/*
2 * Copyright (C) 2012-2013 by Marc Duerner
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * As a special exception, you may use this file as part of a free
10 * software library without restriction. Specifically, if other files
11 * instantiate templates or use macros or inline functions from this
12 * file, or you compile this file and link it with other files to
13 * produce an executable, this file does not by itself cause the
14 * resulting executable to be covered by the GNU General Public
15 * License. This exception does not however invalidate any other
16 * reasons why the executable file might be covered by the GNU Library
17 * General Public License.
18 *
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 */
28
29#ifndef Pt_XmlRpc_HttpClient_h
30#define Pt_XmlRpc_HttpClient_h
31
32#include <Pt/XmlRpc/Api.h>
33#include <Pt/XmlRpc/Client.h>
34#include <Pt/Http/Client.h>
35#include <Pt/Connectable.h>
36#include <Pt/Types.h>
37#include <string>
38
39namespace Pt {
40
41namespace XmlRpc {
42
45class PT_XMLRPC_API HttpClient : public Client
46 , public Connectable
47{
48 public:
52
55 HttpClient(const Net::Endpoint& ep, const std::string& url);
56
60
64 const std::string& url);
65
68 virtual ~HttpClient();
69
73
77
81
84 void setPeerName(const std::string& peer);
85
89
92 void setTimeout(std::size_t timeout);
93
96 void setTarget(const Net::Endpoint& ep, const std::string& url);
97
100 void setTarget(const Net::Endpoint& ep, const Net::TcpSocketOptions& opts,
101 const std::string& url);
102
105 void setHost(const Net::Endpoint& ep);
106
109 void setHost(const Net::Endpoint& ep, const Net::TcpSocketOptions& opts);
110
113 void setServiceUrl(const std::string& url);
114
117 void setServiceUrl(const char* url);
118
121 const Net::Endpoint& host() const;
122
123 Pt::Http::Request& request();
124
125 Pt::Http::Reply& reply();
126
129 void close();
130
131 protected:
132 virtual bool isFailed() const;
133
134 // inheritdoc
135 virtual void onBeginInvoke();
136
137 // inheritdoc
138 virtual void onInvoke();
139
140 // inheritdoc
141 virtual void onEndInvoke();
142
143 // inheritdoc
144 virtual void onCancel();
145
146 private:
153 void setError(bool f = true)
154 { _error = f; }
155
157 void init();
158
160 void onRequest(Http::Client& client);
161
163 void onReply(Http::Client& client);
164
165 private:
166 Http::Client _client;
167 bool _error;
168 Pt::varint_t _r1;
169 Pt::varint_t _r2;
170};
171
172} // namespace XmlRpc
173
174} // namespace Pt
175
176#endif // Pt_XmlRpc_HttpClient_h
Connectable()
Default constructor.
HTTP user agent.
Definition Client.h:189
HTTP reply message.
Definition Reply.h:64
HTTP request message.
Definition Request.h:65
Host and service address.
Definition Endpoint.h:77
TCP socket connection options.
Definition TcpSocket.h:51
Shared configuration for SSL connections.
Definition Context.h:113
Event loop of a thread or process.
Definition EventLoop.h:83
Client()
Constructor.
void setSecure(Ssl::Context &ctx)
Sets SSL context.
const Net::Endpoint & host() const
Returns target host.
void setKeepAlive()
Enables HTTP keep-alive.
HttpClient(System::EventLoop &loop, const Net::Endpoint &ep, const std::string &url)
Construct with host and service URL.
void setTarget(const Net::Endpoint &ep, const std::string &url)
Sets target host and service URL.
HttpClient()
Constructor.
void setTarget(const Net::Endpoint &ep, const Net::TcpSocketOptions &opts, const std::string &url)
Sets target host and service URL.
virtual void onCancel()
Cancels the remote procedure call.
HttpClient(System::EventLoop &loop)
Construct with EventLoop used for I/O.
void setTimeout(std::size_t timeout)
Sets timeout for I/O operations.
virtual void onBeginInvoke()
An asynchronous remote procedure is invoked.
void close()
Closes the connection.
void setHost(const Net::Endpoint &ep)
Sets host to connect.
void setServiceUrl(const std::string &url)
Sets the service URL.
void setServiceUrl(const char *url)
Sets the service URL.
virtual bool isFailed() const
Indicates if the procedure has failed.
HttpClient(const Net::Endpoint &ep, const std::string &url)
Construct with host and service URL.
virtual void onInvoke()
A synchronous remote procedure is called.
System::EventLoop * loop() const
Gets the used EventLoop.
void setActive(System::EventLoop &loop)
Sets the EventLoop to use for I/O.
virtual ~HttpClient()
Destructor.
void setHost(const Net::Endpoint &ep, const Net::TcpSocketOptions &opts)
Sets host to connect.
void setPeerName(const std::string &peer)
Set expected SSL peer name.
XML RPC services and clients.
Core module.
Definition Allocator.h:33