2 * Copyright (c) 2014, Peter Thorson. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
11 * * Neither the name of the WebSocket++ Project nor the
12 * names of its contributors may be used to endorse or promote products
13 * derived from this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #ifndef WEBSOCKETPP_CONFIG_CORE_HPP
29 #define WEBSOCKETPP_CONFIG_CORE_HPP
31 // Non-Policy common stuff
32 #include <websocketpp/common/platforms.hpp>
33 #include <websocketpp/common/cpp11.hpp>
34 #include <websocketpp/common/stdint.hpp>
37 #include <websocketpp/concurrency/basic.hpp>
40 #include <websocketpp/transport/iostream/endpoint.hpp>
43 #include <websocketpp/http/request.hpp>
44 #include <websocketpp/http/response.hpp>
47 #include <websocketpp/message_buffer/message.hpp>
48 #include <websocketpp/message_buffer/alloc.hpp>
51 #include <websocketpp/logger/basic.hpp>
54 #include <websocketpp/random/none.hpp>
56 // User stub base classes
57 #include <websocketpp/endpoint_base.hpp>
58 #include <websocketpp/connection_base.hpp>
61 #include <websocketpp/extensions/permessage_deflate/disabled.hpp>
63 namespace websocketpp {
66 /// Server config with iostream transport
71 typedef websocketpp::concurrency::basic concurrency_type;
73 // HTTP Parser Policies
74 typedef http::parser::request request_type;
75 typedef http::parser::response response_type;
78 typedef message_buffer::message<message_buffer::alloc::con_msg_manager>
80 typedef message_buffer::alloc::con_msg_manager<message_type>
82 typedef message_buffer::alloc::endpoint_msg_manager<con_msg_manager_type>
83 endpoint_msg_manager_type;
86 typedef websocketpp::log::basic<concurrency_type,
87 websocketpp::log::elevel> elog_type;
88 typedef websocketpp::log::basic<concurrency_type,
89 websocketpp::log::alevel> alog_type;
92 typedef websocketpp::random::none::int_generator<uint32_t> rng_type;
94 /// Controls compile time enabling/disabling of thread syncronization
95 /// code Disabling can provide a minor performance improvement to single
96 /// threaded applications
97 static bool const enable_multithreading = true;
99 struct transport_config {
100 typedef type::concurrency_type concurrency_type;
101 typedef type::elog_type elog_type;
102 typedef type::alog_type alog_type;
103 typedef type::request_type request_type;
104 typedef type::response_type response_type;
106 /// Controls compile time enabling/disabling of thread syncronization
107 /// code Disabling can provide a minor performance improvement to single
108 /// threaded applications
109 static bool const enable_multithreading = true;
111 /// Default timer values (in ms)
113 /// Length of time to wait for socket pre-initialization
115 * Exactly what this includes depends on the socket policy in use
117 static const long timeout_socket_pre_init = 5000;
119 /// Length of time to wait before a proxy handshake is aborted
120 static const long timeout_proxy = 5000;
122 /// Length of time to wait for socket post-initialization
124 * Exactly what this includes depends on the socket policy in use.
125 * Often this means the TLS handshake
127 static const long timeout_socket_post_init = 5000;
129 /// Length of time to wait for dns resolution
130 static const long timeout_dns_resolve = 5000;
132 /// Length of time to wait for TCP connect
133 static const long timeout_connect = 5000;
135 /// Length of time to wait for socket shutdown
136 static const long timeout_socket_shutdown = 5000;
139 /// Transport Endpoint Component
140 typedef websocketpp::transport::iostream::endpoint<transport_config>
143 /// User overridable Endpoint base class
144 typedef websocketpp::endpoint_base endpoint_base;
145 /// User overridable Connection base class
146 typedef websocketpp::connection_base connection_base;
148 /// Default timer values (in ms)
150 /// Length of time before an opening handshake is aborted
151 static const long timeout_open_handshake = 5000;
152 /// Length of time before a closing handshake is aborted
153 static const long timeout_close_handshake = 5000;
154 /// Length of time to wait for a pong after a ping
155 static const long timeout_pong = 5000;
157 /// WebSocket Protocol version to use as a client
159 * What version of the WebSocket Protocol to use for outgoing client
160 * connections. Setting this to a value other than 13 (RFC6455) is not
163 static const int client_version = 13; // RFC6455
165 /// Default static error logging channels
167 * Which error logging channels to enable at compile time. Channels not
168 * enabled here will be unable to be selected by programs using the library.
169 * This option gives an optimizing compiler the ability to remove entirely
170 * code to test whether or not to print out log messages on a certain
173 * Default is all except for development/debug level errors
175 static const websocketpp::log::level elog_level =
176 websocketpp::log::elevel::all ^ websocketpp::log::elevel::devel;
178 /// Default static access logging channels
180 * Which access logging channels to enable at compile time. Channels not
181 * enabled here will be unable to be selected by programs using the library.
182 * This option gives an optimizing compiler the ability to remove entirely
183 * code to test whether or not to print out log messages on a certain
186 * Default is all except for development/debug level access messages
188 static const websocketpp::log::level alog_level =
189 websocketpp::log::alevel::all ^ websocketpp::log::alevel::devel;
192 static const size_t connection_read_buffer_size = 16384;
194 /// Drop connections immediately on protocol error.
196 * Drop connections on protocol error rather than sending a close frame.
197 * Off by default. This may result in legit messages near the error being
198 * dropped as well. It may free up resources otherwise spent dealing with
199 * misbehaving clients.
201 static const bool drop_on_protocol_error = false;
203 /// Suppresses the return of detailed connection close information
205 * Silence close suppresses the return of detailed connection close
206 * information during the closing handshake. This information is useful
207 * for debugging and presenting useful errors to end users but may be
208 * undesirable for security reasons in some production environments.
209 * Close reasons could be used by an attacker to confirm that the endpoint
210 * is out of resources or be used to identify the WebSocket implementation
213 * Note: this will suppress *all* close codes, including those explicitly
214 * sent by local applications.
216 static const bool silent_close = false;
218 /// Default maximum message size
220 * Default value for the processor's maximum message size. Maximum message size
221 * determines the point at which the library will fail a connection with the
222 * message_too_big protocol error.
224 * The default is 32MB
228 static const size_t max_message_size = 32000000;
230 /// Default maximum http body size
232 * Default value for the http parser's maximum body size. Maximum body size
233 * determines the point at which the library will abort reading an HTTP
234 * connection with the 413/request entity too large error.
236 * The default is 32MB
240 static const size_t max_http_body_size = 32000000;
242 /// Global flag for enabling/disabling extensions
243 static const bool enable_extensions = true;
245 /// Extension specific settings:
247 /// permessage_compress extension
248 struct permessage_deflate_config {
249 typedef core::request_type request_type;
251 /// If the remote endpoint requests that we reset the compression
252 /// context after each message should we honor the request?
253 static const bool allow_disabling_context_takeover = true;
255 /// If the remote endpoint requests that we reduce the size of the
256 /// LZ77 sliding window size this is the lowest value that will be
257 /// allowed. Values range from 8 to 15. A value of 8 means we will
258 /// allow any possible window size. A value of 15 means do not allow
259 /// negotiation of the window size (ie require the default).
260 static const uint8_t minimum_outgoing_window_bits = 8;
263 typedef websocketpp::extensions::permessage_deflate::disabled
264 <permessage_deflate_config> permessage_deflate_type;
266 /// Autonegotiate permessage-deflate
268 * Automatically enables the permessage-deflate extension.
270 * For clients this results in a permessage-deflate extension request being
271 * sent with every request rather than requiring it to be requested manually
273 * For servers this results in accepting the first set of extension settings
274 * requested by the client that we understand being used. The alternative is
275 * requiring the extension to be manually negotiated in `validate`. With
276 * auto-negotiate on, you may still override the auto-negotiate manually if
279 //static const bool autonegotiate_compression = false;
282 } // namespace config
283 } // namespace websocketpp
285 #endif // WEBSOCKETPP_CONFIG_CORE_HPP