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 
39 namespace Pt {
40 
41 namespace XmlRpc {
42 
45 class PT_XMLRPC_API HttpClient : public Client
46  , public Connectable
47 {
48  public:
51  HttpClient();
52 
55  HttpClient(const Net::Endpoint& ep, const std::string& url);
56 
60 
63  HttpClient(System::EventLoop& loop, const Net::Endpoint& ep,
64  const std::string& url);
65 
68  virtual ~HttpClient();
69 
72  void setActive(System::EventLoop& loop);
73 
76  System::EventLoop* loop() const;
77 
80  void setSecure(Ssl::Context& ctx);
81 
84  void setPeerName(const std::string& peer);
85 
88  void setKeepAlive();
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
TCP socket options.
Definition: TcpSocket.h:48
HTTP request message.
Definition: Request.h:43
Connection Management for Signal and Slot Objects.
Definition: Connectable.h:49
An HTTP client.
Definition: Client.h:74
A client for remote procedure calls.
Definition: Client.h:52
HTTP reply message.
Definition: Reply.h:43
A client for remote procedure calls via HTTP.
Definition: HttpClient.h:45
Context for SSL connections.
Definition: Context.h:76
Represents a Network Host.
Definition: Endpoint.h:46
Thread-safe event loop supporting I/O multiplexing and Timers.
Definition: EventLoop.h:72