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:
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 
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
Core module.
Definition: pt-gfx-images.dox:14
HTTP request message.
Definition: Request.h:44
HTTP reply message.
Definition: Reply.h:44
void setTarget(const Net::Endpoint &ep, const std::string &url)
Sets target host and service URL.
void setPeerName(const std::string &peer)
Set expected SSL peer name.
HttpClient(System::EventLoop &loop, const Net::Endpoint &ep, const std::string &url)
Construct with host and service URL.
virtual void onBeginInvoke()
An asynchronous remote procedure is invoked.
A client for remote procedure calls.
Definition: Client.h:53
virtual bool isFailed() const
Indicates if the procedure has failed.
HttpClient()
Constructor.
System::EventLoop * loop() const
Gets the used EventLoop.
virtual void onCancel()
Cancels the remote procedure call.
void setServiceUrl(const char *url)
Sets the service URL.
void setServiceUrl(const std::string &url)
Sets the service URL.
HttpClient(System::EventLoop &loop)
Construct with EventLoop used for I/O.
void setTarget(const Net::Endpoint &ep, const Net::TcpSocketOptions &opts, const std::string &url)
Sets target host and service URL.
Connection Management for Signal and Slot Objects.
Definition: Connectable.h:50
A client for remote procedure calls via HTTP.
Definition: HttpClient.h:47
Represents a Network Host.
Definition: Endpoint.h:47
void setActive(System::EventLoop &loop)
Sets the EventLoop to use for I/O.
void setHost(const Net::Endpoint &ep, const Net::TcpSocketOptions &opts)
Sets host to connect.
An HTTP client.
Definition: Client.h:78
Thread-safe event loop supporting I/O multiplexing and Timers.
Definition: EventLoop.h:74
virtual void onInvoke()
A synchronous remote procedure is called.
void setHost(const Net::Endpoint &ep)
Sets host to connect.
void setSecure(Ssl::Context &ctx)
Sets SSL context.
void setTimeout(std::size_t timeout)
Sets timeout for I/O operations.
void setKeepAlive()
Enables HTTP keep-alive.
virtual ~HttpClient()
Destructor.
const Net::Endpoint & host() const
Returns target host.
TCP socket options.
Definition: TcpSocket.h:49
HttpClient(const Net::Endpoint &ep, const std::string &url)
Construct with host and service URL.
void close()
Closes the connection.
Context for SSL connections.
Definition: Context.h:80