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 
63  void setActive(System::EventLoop& loop);
64 
67  System::EventLoop* loop() const;
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
TCP socket options.
Definition: TcpSocket.h:48
HTTP request message.
Definition: Request.h:43
A client for SOAP via HTTP.
Definition: HttpClient.h:45
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:54
HTTP reply message.
Definition: Reply.h:43
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