|
| 1 | +/* |
| 2 | + This file is part of libhttpserver |
| 3 | + Copyright (C) 2011-2019 Sebastiano Merlino |
| 4 | +
|
| 5 | + This library is free software; you can redistribute it and/or |
| 6 | + modify it under the terms of the GNU Lesser General Public |
| 7 | + License as published by the Free Software Foundation; either |
| 8 | + version 2.1 of the License, or (at your option) any later version. |
| 9 | +
|
| 10 | + This library is distributed in the hope that it will be useful, |
| 11 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | + Lesser General Public License for more details. |
| 14 | +
|
| 15 | + You should have received a copy of the GNU Lesser General Public |
| 16 | + License along with this library; if not, write to the Free Software |
| 17 | + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
| 18 | + USA |
| 19 | +*/ |
| 20 | + |
| 21 | +#if !defined (_HTTPSERVER_HPP_INSIDE_) && !defined (HTTPSERVER_COMPILATION) |
| 22 | +#error "Only <httpserver.hpp> or <httpserverpp> can be included directly." |
| 23 | +#endif |
| 24 | + |
| 25 | +#ifndef SRC_HTTPSERVER_CONSTANTS_HPP_ |
| 26 | +#define SRC_HTTPSERVER_CONSTANTS_HPP_ |
| 27 | + |
| 28 | +#include <cstdint> |
| 29 | +#include <string_view> |
| 30 | + |
| 31 | +// Public, namespaced replacements for the v1 #define wall. Each constant |
| 32 | +// here was previously a value-form macro in a public header (see PRD-CFG- |
| 33 | +// REQ-002 / architecture §4.9 for the rationale). The identifiers |
| 34 | +// preserve their v1 spellings so the migration is mechanical: only the |
| 35 | +// namespace qualifier changes at call sites. |
| 36 | +// |
| 37 | +// `inline constexpr` (C++17+, project floor is C++20 per TASK-001) gives |
| 38 | +// each symbol a single ODR-stable definition usable from any TU that |
| 39 | +// includes this header. |
| 40 | +namespace httpserver::constants { |
| 41 | + |
| 42 | +// Default TCP port the webserver binds to when no `port()` is set on the |
| 43 | +// create_webserver builder. Replaces v1 `#define DEFAULT_WS_PORT 9898`. |
| 44 | +inline constexpr std::uint16_t DEFAULT_WS_PORT = 9898; |
| 45 | + |
| 46 | +// Default per-connection timeout in seconds. Replaces v1 |
| 47 | +// `#define DEFAULT_WS_TIMEOUT 180`. Type is `int` to match the |
| 48 | +// `create_webserver._connection_timeout` field exactly — no implicit |
| 49 | +// conversion at the assignment site, no -Wconversion noise. The value |
| 50 | +// is non-negative by construction. |
| 51 | +inline constexpr int DEFAULT_WS_TIMEOUT = 180; |
| 52 | + |
| 53 | +// Bitmask sentinel used by ip_representation when no explicit CIDR mask |
| 54 | +// has been parsed (all 16 nibbles "present"). Replaces v1 |
| 55 | +// `#define DEFAULT_MASK_VALUE 0xFFFF`. |
| 56 | +inline constexpr std::uint16_t DEFAULT_MASK_VALUE = 0xFFFFu; |
| 57 | + |
| 58 | +// Default body for a 404 response when no not_found_resource is set on |
| 59 | +// the webserver. Replaces v1 `#define NOT_FOUND_ERROR "Not Found"`. |
| 60 | +// std::string_view keeps storage non-allocating; call sites materialize |
| 61 | +// a std::string via the string_response constructor. |
| 62 | +inline constexpr std::string_view NOT_FOUND_ERROR = "Not Found"; |
| 63 | + |
| 64 | +// Default body for a 405 response when no method_not_allowed_resource |
| 65 | +// is set. Replaces v1 `#define METHOD_ERROR "Method not Allowed"`. |
| 66 | +// The name is preserved (rather than renamed to METHOD_NOT_ALLOWED_ERROR) |
| 67 | +// to keep the migration mechanical — the namespacing is the API change, |
| 68 | +// not a rename. |
| 69 | +inline constexpr std::string_view METHOD_ERROR = "Method not Allowed"; |
| 70 | + |
| 71 | +// Default body for a 406 response. Replaces v1 |
| 72 | +// `#define NOT_METHOD_ERROR "Method not Acceptable"`. Currently unused |
| 73 | +// by any in-tree caller (verified by grep across src/, test/, examples/); |
| 74 | +// retained for v1 API parity per the v2.0 mechanical-migration policy. |
| 75 | +inline constexpr std::string_view NOT_METHOD_ERROR = "Method not Acceptable"; |
| 76 | + |
| 77 | +// Default body for a 500 response when no internal_error_resource is |
| 78 | +// set. Replaces v1 `#define GENERIC_ERROR "Internal Error"`. |
| 79 | +inline constexpr std::string_view GENERIC_ERROR = "Internal Error"; |
| 80 | + |
| 81 | +} // namespace httpserver::constants |
| 82 | + |
| 83 | +#endif // SRC_HTTPSERVER_CONSTANTS_HPP_ |
0 commit comments