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_MINIMAL_HPP
29 #define WEBSOCKETPP_CONFIG_MINIMAL_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/none.hpp>
40 #include <websocketpp/transport/stub/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/stub.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 minimal dependencies
68 * This config strips out as many dependencies as possible. It is suitable for
69 * use as a base class for custom configs that want to implement or choose their
70 * own policies for components that even the core config includes.
72 * NOTE: this config stubs out enough that it cannot be used directly. You must
73 * supply at least a transport policy for a config based on `minimal_server` to
76 * Present dependency list for minimal_server config:
91 * <stdint.h> or <boost/cstdint.hpp>
92 * <netinet/in.h> or <winsock2.h> (for ntohl.. could potentially bundle this)
96 struct minimal_server {
97 typedef minimal_server type;
100 typedef websocketpp::concurrency::none concurrency_type;
102 // HTTP Parser Policies
103 typedef http::parser::request request_type;
104 typedef http::parser::response response_type;
107 typedef message_buffer::message<message_buffer::alloc::con_msg_manager>
109 typedef message_buffer::alloc::con_msg_manager<message_type>
110 con_msg_manager_type;
111 typedef message_buffer::alloc::endpoint_msg_manager<con_msg_manager_type>
112 endpoint_msg_manager_type;
115 typedef websocketpp::log::stub elog_type;
116 typedef websocketpp::log::stub alog_type;
119 typedef websocketpp::random::none::int_generator<uint32_t> rng_type;
121 /// Controls compile time enabling/disabling of thread syncronization
122 /// code Disabling can provide a minor performance improvement to single
123 /// threaded applications
124 static bool const enable_multithreading = true;
126 struct transport_config {
127 typedef type::concurrency_type concurrency_type;
128 typedef type::elog_type elog_type;
129 typedef type::alog_type alog_type;
130 typedef type::request_type request_type;
131 typedef type::response_type response_type;
133 /// Controls compile time enabling/disabling of thread syncronization
134 /// code Disabling can provide a minor performance improvement to single
135 /// threaded applications
136 static bool const enable_multithreading = true;
138 /// Default timer values (in ms)
140 /// Length of time to wait for socket pre-initialization
142 * Exactly what this includes depends on the socket policy in use
144 static const long timeout_socket_pre_init = 5000;
146 /// Length of time to wait before a proxy handshake is aborted
147 static const long timeout_proxy = 5000;
149 /// Length of time to wait for socket post-initialization
151 * Exactly what this includes depends on the socket policy in use.
152 * Often this means the TLS handshake
154 static const long timeout_socket_post_init = 5000;
156 /// Length of time to wait for dns resolution
157 static const long timeout_dns_resolve = 5000;
159 /// Length of time to wait for TCP connect
160 static const long timeout_connect = 5000;
162 /// Length of time to wait for socket shutdown
163 static const long timeout_socket_shutdown = 5000;
166 /// Transport Endpoint Component
167 typedef websocketpp::transport::stub::endpoint<transport_config>
170 /// User overridable Endpoint base class
171 typedef websocketpp::endpoint_base endpoint_base;
172 /// User overridable Connection base class
173 typedef websocketpp::connection_base connection_base;
175 /// Default timer values (in ms)
177 /// Length of time before an opening handshake is aborted
178 static const long timeout_open_handshake = 5000;
179 /// Length of time before a closing handshake is aborted
180 static const long timeout_close_handshake = 5000;
181 /// Length of time to wait for a pong after a ping
182 static const long timeout_pong = 5000;
184 /// WebSocket Protocol version to use as a client
186 * What version of the WebSocket Protocol to use for outgoing client
187 * connections. Setting this to a value other than 13 (RFC6455) is not
190 static const int client_version = 13; // RFC6455
192 /// Default static error logging channels
194 * Which error logging channels to enable at compile time. Channels not
195 * enabled here will be unable to be selected by programs using the library.
196 * This option gives an optimizing compiler the ability to remove entirely
197 * code to test whether or not to print out log messages on a certain
200 * Default is all except for development/debug level errors
202 static const websocketpp::log::level elog_level =
203 websocketpp::log::elevel::none;
205 /// Default static access logging channels
207 * Which access logging channels to enable at compile time. Channels not
208 * enabled here will be unable to be selected by programs using the library.
209 * This option gives an optimizing compiler the ability to remove entirely
210 * code to test whether or not to print out log messages on a certain
213 * Default is all except for development/debug level access messages
215 static const websocketpp::log::level alog_level =
216 websocketpp::log::alevel::none;
219 static const size_t connection_read_buffer_size = 16384;
221 /// Drop connections immediately on protocol error.
223 * Drop connections on protocol error rather than sending a close frame.
224 * Off by default. This may result in legit messages near the error being
225 * dropped as well. It may free up resources otherwise spent dealing with
226 * misbehaving clients.
228 static const bool drop_on_protocol_error = false;
230 /// Suppresses the return of detailed connection close information
232 * Silence close suppresses the return of detailed connection close
233 * information during the closing handshake. This information is useful
234 * for debugging and presenting useful errors to end users but may be
235 * undesirable for security reasons in some production environments.
236 * Close reasons could be used by an attacker to confirm that the endpoint
237 * is out of resources or be used to identify the WebSocket implementation
240 * Note: this will suppress *all* close codes, including those explicitly
241 * sent by local applications.
243 static const bool silent_close = false;
245 /// Default maximum message size
247 * Default value for the processor's maximum message size. Maximum message size
248 * determines the point at which the library will fail a connection with the
249 * message_too_big protocol error.
251 * The default is 32MB
253 * @since 0.4.0-alpha1
255 static const size_t max_message_size = 32000000;
257 /// Default maximum http body size
259 * Default value for the http parser's maximum body size. Maximum body size
260 * determines the point at which the library will abort reading an HTTP
261 * connection with the 413/request entity too large error.
263 * The default is 32MB
267 static const size_t max_http_body_size = 32000000;
269 /// Global flag for enabling/disabling extensions
270 static const bool enable_extensions = true;
272 /// Extension specific settings:
274 /// permessage_compress extension
275 struct permessage_deflate_config {
276 typedef core::request_type request_type;
278 /// If the remote endpoint requests that we reset the compression
279 /// context after each message should we honor the request?
280 static const bool allow_disabling_context_takeover = true;
282 /// If the remote endpoint requests that we reduce the size of the
283 /// LZ77 sliding window size this is the lowest value that will be
284 /// allowed. Values range from 8 to 15. A value of 8 means we will
285 /// allow any possible window size. A value of 15 means do not allow
286 /// negotiation of the window size (ie require the default).
287 static const uint8_t minimum_outgoing_window_bits = 8;
290 typedef websocketpp::extensions::permessage_deflate::disabled
291 <permessage_deflate_config> permessage_deflate_type;
293 /// Autonegotiate permessage-deflate
295 * Automatically enables the permessage-deflate extension.
297 * For clients this results in a permessage-deflate extension request being
298 * sent with every request rather than requiring it to be requested manually
300 * For servers this results in accepting the first set of extension settings
301 * requested by the client that we understand being used. The alternative is
302 * requiring the extension to be manually negotiated in `validate`. With
303 * auto-negotiate on, you may still override the auto-negotiate manually if
306 //static const bool autonegotiate_compression = false;
309 } // namespace config
310 } // namespace websocketpp
312 #endif // WEBSOCKETPP_CONFIG_MINIMAL_HPP