|
- #pragma once
-
- #include <microhttpd.h>
- #include <cppcore/misc/flags.h>
- #include <cppcore/misc/exception.h>
-
- namespace cppmicrohttpd
- {
-
- /**
- * @brief Flags to create the daemon with.
- */
- enum class daemon_flag
- : unsigned int
- {
- /**
- * Run in debug mode. If this flag is used, the library should print error messages and warnings to stderr.
- * Note that for this run-time option to have any effect, MHD needs to be compiled with messages enabled.
- * This is done by default except you ran configure with the --disable-messages flag set.
- */
- use_debug = MHD_USE_DEBUG,
-
- /**
- * Run in HTTPS-mode. If you specify MHD_USE_SSL and MHD was compiled without SSL support, MHD_start_daemon
- * will return NULL.
- */
- use_ssl = MHD_USE_SSL,
-
- /**
- * Run using one thread per connection.
- */
- use_thread_per_connection = MHD_USE_THREAD_PER_CONNECTION,
-
- /**
- * Run using an internal thread doing SELECT.
- */
- use_select_internally = MHD_USE_SELECT_INTERNALLY,
-
- /**
- * Run using the IPv6 protocol (otherwise, MHD will just support IPv4). If you specify MHD_USE_IPV6 and the
- * local platform does not support it, MHD_start_daemon will return NULL.
- *
- * If you want MHD to support IPv4 and IPv6 using a single socket, pass MHD_USE_DUAL_STACK, otherwise,
- * if you only pass this option, MHD will try to bind to IPv6-only (resulting in no IPv4 support).
- */
- use_ipv6 = MHD_USE_IPv6,
-
- /**
- * Use a single socket for IPv4 and IPv6. Note that this will mean that IPv4 addresses are returned by MHD in
- * the IPv6-mapped format (the ’struct sockaddr_in6’ format will be used for IPv4 and IPv6).
- */
- use_dual_stack = MHD_USE_DUAL_STACK,
-
- /**
- * Be pedantic about the protocol (as opposed to as tolerant as possible). Specifically, at the moment,
- * this flag causes MHD to reject HTTP 1.1 connections without a Host header. This is required by the standard,
- * but of course in violation of the “be as liberal as possible in what you accept” norm. It is recommended to
- * turn this ON if you are testing clients against MHD, and OFF in production.
- */
- use_pedantic_checks = MHD_USE_PEDANTIC_CHECKS,
-
- /**
- * Use poll() instead of select(). This allows sockets with descriptors >= ::cppcore::fdsetSIZE. This option currently only
- * works in conjunction with MHD_USE_THREAD_PER_CONNECTION or MHD_USE_INTERNAL_SELECT (at this point).
- * If you specify MHD_USE_POLL and the local platform does not support it, MHD_start_daemon will return NULL.
- */
- use_poll = MHD_USE_POLL,
-
- /**
- * Suppress (automatically) adding the ’Date:’ header to HTTP responses. This option should ONLY be used on
- * systems that do not have a clock and that DO provide other mechanisms for cache control.
- * See also RFC 2616, section 14.18 (exception 3).
- */
- supress_date_no_clock = MHD_SUPPRESS_DATE_NO_CLOCK,
-
- /**
- * Run the HTTP server without any listen socket. This option only makes sense if MHD_add_connection is going
- * to be used exclusively to connect HTTP clients to the HTTP server. This option is incompatible with using
- * a thread pool; if it is used, MHD_OPTION_THREAD_POOL_SIZE is ignored.
- */
- use_no_listen_socket = MHD_USE_NO_LISTEN_SOCKET,
-
- /**
- * Force MHD to use a signal pipe to notify the event loop (of threads) of our shutdown. This is required if
- * an appliction uses MHD_USE_INTERNAL_SELECT or MHD_USE_THREAD_PER_CONNECTION and then performs MHD_quiesce_daemon
- * (which eliminates our ability to signal termination via the listen socket). In these modes, MHD_quiesce_daemon
- * will fail if this option was not set. Also, use of this option is automatic (as in, you do not even have to
- * specify it), if MHD_USE_NO_LISTEN_SOCKET is specified. In "external" select mode, this option is always simply
- * ignored.
- *
- * Using this option also guarantees that MHD will not call shutdown() on the listen socket, which means a parent
- * process can continue to use the socket.
- */
- use_pipe_for_shutdown = MHD_USE_PIPE_FOR_SHUTDOWN,
-
- /**
- * Enables using MHD_suspend_connection and MHD_resume_connection, as performing these calls requires some additional
- * pipes to be created, and code not using these calls should not pay the cost.
- */
- use_suspend_resume = MHD_USE_SUSPEND_RESUME,
-
- /**
- * Enable TCP_FASTOPEN on the listen socket. TCP_FASTOPEN is currently supported on Linux >= 3.6. On other systems
- * using this option with cause MHD_start_daemon to fail.
- */
- use_tcp_fastopen = MHD_USE_TCP_FASTOPEN,
- };
-
- using daemon_flags = ::cppcore::simple_flags<daemon_flag>;
-
- /**
- * @brief Flag to indicate which callbacks should be registerd in MHC.
- */
- enum class callback_flag
- {
-
- };
-
- using callback_flags = ::cppcore::shifted_flags<callback_flag>;
-
- /**
- * @brief Exception with the error code and error string from the MHD library.
- */
- struct exception
- : public ::cppcore::exception
- {
- public:
- using ::cppcore::exception::exception;
- };
-
- struct http_exception
- : public ::cppcore::exception
- {
- uint status; //!< HTTP status code.
-
- /**
- * @brief Constructor.
- *
- * @param[in] p_status HTTP status code.
- * @param[in] p_message Actual error message.
- */
- inline http_exception(
- uint p_status,
- const std::string& p_message);
- };
-
- }
-
- #include "types.inl"
|