HttpClient.h
1 /*
2  * Copyright (C) 2012-2014 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_Soap_HttpClient_h
30 #define Pt_Soap_HttpClient_h
31 
32 #include <Pt/Soap/Api.h>
33 #include <Pt/Soap/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 Soap {
42 
45 class PT_SOAP_API HttpClient : public Client
46  , public Connectable
47 {
48  public:
51  HttpClient(ServiceDeclaration& service);
52 
55  HttpClient(ServiceDeclaration& service, System::EventLoop& loop);
56 
59  virtual ~HttpClient();
60 
64 
68 
71  void setSecure(Ssl::Context& ctx);
72 
75  void setPeerName(const std::string& peer);
76 
79  void setKeepAlive();
80 
83  void setTimeout(std::size_t timeout);
84 
87  void setTarget(const Net::Endpoint& ep, const std::string& url);
88 
91  void setTarget(const Net::Endpoint& ep, const Net::TcpSocketOptions& opts,
92  const std::string& url);
93 
96  void setHost(const Net::Endpoint& ep);
97 
100  void setHost(const Net::Endpoint& ep, const Net::TcpSocketOptions& opts);
101 
104  void setServiceUrl(const std::string& url);
105 
108  void setServiceUrl(const char* url);
109 
112  const Net::Endpoint& host() const;
113 
114  Pt::Http::Request& request();
115 
116  Pt::Http::Reply& reply();
117 
120  void close();
121 
122  protected:
123  virtual bool isFailed() const;
124 
125  // inheritdoc
126  virtual void onBeginInvoke();
127 
128  // inheritdoc
129  virtual void onInvoke();
130 
131  // inheritdoc
132  virtual void onEndInvoke();
133 
134  // inheritdoc
135  virtual void onCancel();
136 
137  private:
144  void setError(bool f = true)
145  { _error = f; }
146 
148  void init();
149 
151  void onRequest(Http::Client& client);
152 
154  void onReply(Http::Client& client);
155 
156  private:
157  Http::Client _client;
158  bool _error;
159  Pt::varint_t _r1;
160  Pt::varint_t _r2;
161 };
162 
163 } // namespace Soap
164 
165 } // namespace Pt
166 
167 #endif // Pt_Soap_HttpClient_h
Core module.
Definition: pt-gfx-images.dox:14
void setActive(System::EventLoop &loop)
Sets the EventLoop to use for I/O.
HTTP request message.
Definition: Request.h:44
HttpClient(ServiceDeclaration &service, System::EventLoop &loop)
Construct with EventLoop used for I/O.
HTTP reply message.
Definition: Reply.h:44
void setHost(const Net::Endpoint &ep, const Net::TcpSocketOptions &opts)
Sets host to connect.
A client for SOAP via HTTP.
Definition: HttpClient.h:47
const Net::Endpoint & host() const
Returns target host.
void setSecure(Ssl::Context &ctx)
Sets SSL context.
void setTarget(const Net::Endpoint &ep, const Net::TcpSocketOptions &opts, const std::string &url)
Sets target host and service URL.
void setKeepAlive()
Enables HTTP keep-alive.
HttpClient(ServiceDeclaration &service)
Constructor.
Connection Management for Signal and Slot Objects.
Definition: Connectable.h:50
virtual bool isFailed() const
Indicates if the procedure has failed.
virtual void onBeginInvoke()
An asynchronous remote procedure is invoked.
Represents a Network Host.
Definition: Endpoint.h:47
void close()
Closes the connection.
void setTarget(const Net::Endpoint &ep, const std::string &url)
Sets target host and service URL.
virtual void onInvoke()
A synchronous remote procedure is called.
void setTimeout(std::size_t timeout)
Sets timeout for I/O operations.
virtual void onCancel()
Cancels the remote procedure call.
An HTTP client.
Definition: Client.h:78
Thread-safe event loop supporting I/O multiplexing and Timers.
Definition: EventLoop.h:74
System::EventLoop * loop() const
Gets the used EventLoop.
void setPeerName(const std::string &peer)
Set expected SSL peer name.
void setServiceUrl(const char *url)
Sets the service URL.
A client for remote procedure calls.
Definition: Client.h:55
TCP socket options.
Definition: TcpSocket.h:49
virtual ~HttpClient()
Destructor.
void setHost(const Net::Endpoint &ep)
Sets host to connect.
Context for SSL connections.
Definition: Context.h:80
void setServiceUrl(const std::string &url)
Sets the service URL.