Kea  1.5.0
client.h
Go to the documentation of this file.
1 // Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #ifndef HTTP_CLIENT_H
8 #define HTTP_CLIENT_H
9 
10 #include <asiolink/io_service.h>
11 #include <exceptions/exceptions.h>
12 #include <http/url.h>
13 #include <http/request.h>
14 #include <http/response.h>
15 #include <boost/shared_ptr.hpp>
16 #include <functional>
17 #include <string>
18 
19 namespace isc {
20 namespace http {
21 
23 class HttpClientError : public Exception {
24 public:
25  HttpClientError(const char* file, size_t line, const char* what) :
26  isc::Exception(file, line, what) { };
27 };
28 
29 class HttpClientImpl;
30 
66 class HttpClient {
67 public:
68 
70  struct RequestTimeout {
74  explicit RequestTimeout(long value)
75  : value_(value) {
76  }
77  long value_;
78  };
79 
81  typedef std::function<void(const boost::system::error_code&,
82  const HttpResponsePtr&,
83  const std::string&)> RequestHandler;
84 
91  typedef std::function<bool(const boost::system::error_code&)> ConnectHandler;
92 
96  explicit HttpClient(asiolink::IOService& io_service);
97 
163  void asyncSendRequest(const Url& url,
164  const HttpRequestPtr& request,
165  const HttpResponsePtr& response,
166  const RequestHandler& request_callback,
167  const RequestTimeout& request_timeout =
168  RequestTimeout(10000),
169  const ConnectHandler& connect_callback =
170  ConnectHandler());
171 
173  void stop();
174 
175 private:
176 
178  boost::shared_ptr<HttpClientImpl> impl_;
179 };
180 
181 } // end of namespace isc::http
182 } // end of namespace isc
183 
184 #endif
void stop()
Closes all connections.
Definition: client.cc:794
HttpClientError(const char *file, size_t line, const char *what)
Definition: client.h:25
long value_
Timeout value specified.
Definition: client.h:77
std::function< void(const boost::system::error_code &, const HttpResponsePtr &, const std::string &)> RequestHandler
Callback type used in call to HttpClient::asyncSendRequest.
Definition: client.h:83
HTTP request/response timeout value.
Definition: client.h:70
std::function< bool(const boost::system::error_code &)> ConnectHandler
Optional handler invoked when client connects to the server.
Definition: client.h:91
RequestTimeout(long value)
Constructor.
Definition: client.h:74
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Represents an URL.
Definition: url.h:20
void asyncSendRequest(const Url &url, const HttpRequestPtr &request, const HttpResponsePtr &response, const RequestHandler &request_callback, const RequestTimeout &request_timeout=RequestTimeout(10000), const ConnectHandler &connect_callback=ConnectHandler())
Queues new asynchronous HTTP request.
Definition: client.cc:768
boost::shared_ptr< HttpResponse > HttpResponsePtr
Pointer to the HttpResponse object.
Definition: response.h:78
HTTP client class.
Definition: client.h:66
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-dhcp-ddns.
boost::shared_ptr< HttpRequest > HttpRequestPtr
Pointer to the HttpRequest object.
Definition: request.h:25
HttpClient(asiolink::IOService &io_service)
Constructor.
Definition: client.cc:763
A generic error raised by the HttpClient class.
Definition: client.h:23