26 #ifndef _CASA_HTTP_LISTENER_H
27 #define _CASA_HTTP_LISTENER_H
32 #if !defined(_WIN32) && !defined(__cplusplus_winrt)
33 #include <boost/asio/ssl.hpp>
36 #include "cpprest/http_msg.h"
38 #if !defined(_WIN32) || (_WIN32_WINNT >= _WIN32_WINNT_VISTA && !defined(__cplusplus_winrt))
62 : m_timeout(
utility::seconds(120))
70 : m_timeout(other.m_timeout)
72 , m_ssl_context_callback(other.m_ssl_context_callback)
81 : m_timeout(std::move(other.m_timeout))
83 , m_ssl_context_callback(std::move(other.m_ssl_context_callback))
95 m_timeout = rhs.m_timeout;
97 m_ssl_context_callback = rhs.m_ssl_context_callback;
111 m_timeout = std::move(rhs.m_timeout);
113 m_ssl_context_callback = std::move(rhs.m_ssl_context_callback);
134 m_timeout = std::move(timeout);
144 return m_ssl_context_callback;
153 m_ssl_context_callback = ssl_context_callback;
159 utility::seconds m_timeout;
161 std::function<void(boost::asio::ssl::context&)> m_ssl_context_callback;
177 , m_close_task(pplx::task_from_result())
198 std::function<void(http::http_request)> m_all_requests;
199 std::map<http::method, std::function<void(http::http_request)>> m_supported_methods;
208 utility::string_t get_supported_methods()
const;
233 : m_impl(
utility::details::make_unique<details::http_listener_impl>(std::move(address)))
243 : m_impl(
utility::details::make_unique<details::http_listener_impl>(std::move(address), std::move(config)))
253 : m_impl(
utility::details::make_unique<details::http_listener_impl>())
269 return m_impl->open();
285 return m_impl->close();
294 m_impl->m_all_requests = handler;
304 m_impl->m_supported_methods[
method] = handler;
324 : m_impl(std::move(other.m_impl))
336 m_impl = std::move(other.m_impl);
347 std::unique_ptr<details::http_listener_impl> m_impl;
http_listener()
Default constructor.
Definition: http_listener.h:252
utility::seconds timeout() const
Get the timeout
Definition: http_listener.h:123
Configuration class used to set various options when constructing and http_listener instance...
Definition: http_listener.h:54
http_listener(http::uri address)
Create a listener from a URI.
Definition: http_listener.h:232
A flexible, protocol independent URI implementation.
Definition: base_uri.h:151
void support(const http::method &method, const std::function< void(http_request)> &handler)
Add support for a specific HTTP method.
Definition: http_listener.h:302
The web namespace contains functionality common to multiple protocols like HTTP and WebSockets...
Definition: base_uri.h:37
_ASYNCRTIMP ~http_listener()
Destructor frees any held resources.
void support(const std::function< void(http_request)> &handler)
Add a general handler to support all requests.
Definition: http_listener.h:292
http_listener(http_listener &&other)
Move constructor.
Definition: http_listener.h:323
const http_listener_config & configuration() const
Get the configuration of this listener.
Definition: http_listener.h:317
http_listener_config & operator=(http_listener_config &&rhs)
Assignment operator.
Definition: http_listener.h:107
http_listener_config(http_listener_config &&other)
Move constructor.
Definition: http_listener.h:80
pplx::task< void > open()
Asynchronously open the listener, i.e. start accepting requests.
Definition: http_listener.h:267
utility::string_t method
Predefined method strings for the standard HTTP methods mentioned in the HTTP 1.1 specification...
Definition: http_msg.h:62
http_listener_config(const http_listener_config &other)
Copy constructor.
Definition: http_listener.h:69
void set_ssl_context_callback(const std::function< void(boost::asio::ssl::context &)> &ssl_context_callback)
Set the callback of ssl context
Definition: http_listener.h:151
_ASYNCRTIMP void handle_request(http::http_request msg)
Handler for all requests. The HTTP host uses this to dispatch a message to the pipeline.
http_listener_config()
Create an http_listener configuration with default options.
Definition: http_listener.h:61
const http::uri & uri() const
Get the URI of the listener.
Definition: http_listener.h:311
The Parallel Patterns Library (PPL) task class. A task object represents work that can be executed as...
Definition: pplxtasks.h:4173
A class for listening and processing HTTP requests at a specific URI.
Definition: http_listener.h:223
const std::function< void(boost::asio::ssl::context &)> & get_ssl_context_callback() const
Get the callback of ssl context
Definition: http_listener.h:142
Represents an HTTP request.
Definition: http_msg.h:771
http_listener & operator=(http_listener &&other)
Move assignment operator.
Definition: http_listener.h:332
http_listener(http::uri address, http_listener_config config)
Create a listener with specified URI and configuration.
Definition: http_listener.h:242
Internal class for pointer to implementation design pattern.
Definition: http_listener.h:171
void set_timeout(utility::seconds timeout)
Set the timeout
Definition: http_listener.h:132
http_listener_config & operator=(const http_listener_config &rhs)
Assignment operator.
Definition: http_listener.h:91
pplx::task< void > close()
Asynchronously stop accepting requests and close all connections.
Definition: http_listener.h:283
Various utilities for string conversions and date and time manipulation.
Definition: asyncrt_utils.h:50