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
39namespace Pt {
40
41namespace Soap {
42
45class 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
72
75 void setPeerName(const std::string& peer);
76
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
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
Client(ServiceDeclaration &service)
Constructor.
void setSecure(Ssl::Context &ctx)
Sets SSL context.
const Net::Endpoint & host() const
Returns target host.
void setKeepAlive()
Enables HTTP keep-alive.
void setTarget(const Net::Endpoint &ep, const std::string &url)
Sets target host and service URL.
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.
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.
HttpClient(ServiceDeclaration &service)
Constructor.
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.
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.
HttpClient(ServiceDeclaration &service, System::EventLoop &loop)
Construct with EventLoop used 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.
Shared configuration for SSL connections.
Definition Context.h:113
Event loop of a thread or process.
Definition EventLoop.h:83
SOAP services and clients.
Core module.
Definition Allocator.h:33