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>
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
19namespace isc {
20namespace http {
21
23class HttpClientError : public Exception {
24public:
25 HttpClientError(const char* file, size_t line, const char* what) :
26 isc::Exception(file, line, what) { };
27};
28
29class HttpClientImpl;
30
67public:
68
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 =
171
173 void stop();
174
175private:
176
178 boost::shared_ptr<HttpClientImpl> impl_;
179};
180
181} // end of namespace isc::http
182} // end of namespace isc
183
184#endif
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic error raised by the HttpClient class.
Definition: client.h:23
HttpClientError(const char *file, size_t line, const char *what)
Definition: client.h:25
HTTP client class.
Definition: client.h:66
std::function< bool(const boost::system::error_code &)> ConnectHandler
Optional handler invoked when client connects to the server.
Definition: client.h:91
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
void stop()
Closes all connections.
Definition: client.cc:794
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
Represents an URL.
Definition: url.h:20
boost::shared_ptr< HttpResponse > HttpResponsePtr
Pointer to the HttpResponse object.
Definition: response.h:81
boost::shared_ptr< HttpRequest > HttpRequestPtr
Pointer to the HttpRequest object.
Definition: request.h:28
Defines the logger used by the top-level component of kea-dhcp-ddns.
HTTP request/response timeout value.
Definition: client.h:70
RequestTimeout(long value)
Constructor.
Definition: client.h:74
long value_
Timeout value specified.
Definition: client.h:77