FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
libhttpserver/src/httpserver/feature_unavailable.hpp at master · etr/libhttpserver · GitHub
etr
/
libhttpserver
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
190
Star
950
Code
Issues
7
Pull requests
2
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
libhttpserver
/
src
/
httpserver
/
feature_unavailable.hpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
115 lines (106 loc) · 5.12 KB
Breadcrumbs
libhttpserver
/
src
/
httpserver
/
feature_unavailable.hpp
Copy path
File metadata and controls
115 lines (106 loc) · 5.12 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
This file is part of libhttpserver
Copyright (C) 2011-2019 Sebastiano Merlino
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
*/
#
if
!defined (_HTTPSERVER_HPP_INSIDE_) && !defined (HTTPSERVER_COMPILATION)
#
error
"Only <httpserver.hpp> or <httpserverpp> can be included directly."
#
endif
#
ifndef
SRC_HTTPSERVER_FEATURE_UNAVAILABLE_HPP_
#
define
SRC_HTTPSERVER_FEATURE_UNAVAILABLE_HPP_
#
include
<
stdexcept
>
#
include
<
string
>
#
include
<
string_view
>
namespace
httpserver
{
/*
*
* Exception thrown when a build-time-disabled feature is invoked at runtime.
*
* The class is unconditionally available regardless of `HAVE_*` flags so
* that downstream code can always write
* @code
* try { ... } catch (const httpserver::feature_unavailable&) { ... }
* @endcode
* even in builds that compiled out the optional feature in question.
*
* The class is header-only (and inline) on purpose: it has no library
* dependencies, must be cheap to throw from anywhere in the codebase, and
* avoids ABI churn for what is effectively a labelled `std::runtime_error`.
*
* ### Throw sites
*
* The library throws `feature_unavailable` from these sites; each one
* pairs the feature label with the `HAVE_*` build flag that gates it:
*
* - @ref webserver::webserver — thrown at webserver construction time
* when consuming the builder: `use_ssl(true)` on a
* `HAVE_GNUTLS`-off build, `basic_auth(true)` on a
* `HAVE_BAUTH`-off build, or `digest_auth(true)` on a
* `HAVE_DAUTH`-off build. The `create_webserver` setters accept all
* values without throwing; feature-unavailability is validated
* lazily at `webserver` construction, not at the setter call.
* - @ref http_response::unauthorized(digest_challenge) — thrown on a
* `HAVE_DAUTH`-off build. The declaration is unconditional;
* only the definition branches on `HAVE_DAUTH`.
* - @ref webserver::register_ws_resource and
* @ref webserver::unregister_ws_resource — on a `HAVE_WEBSOCKET`-off
* build (every websocket entry point throws this).
* - @ref websocket_session::send_text, @ref websocket_session::send_binary,
* @ref websocket_session::send_ping, @ref websocket_session::send_pong,
* and @ref websocket_session::close — on a `HAVE_WEBSOCKET`-off build,
* so that downstream handlers that capture a session reference get a
* uniform exception type rather than a link-time error.
*
* Catching `feature_unavailable` (or its base `std::runtime_error`) on
* the dispatch path is handled by the standard
* @ref webserver internal_error_handler contract — it surfaces as a
* generic 500 unless the application installs an
* @ref create_webserver::internal_error_handler that special-cases it.
*
* @see create_webserver::use_ssl, create_webserver::basic_auth,
* create_webserver::digest_auth, webserver::register_ws_resource,
* websocket_session
*/
class
feature_unavailable
:
public
std
::runtime_error {
public:
/*
*
* Construct with the feature name and the build flag that gates it.
*
* The resulting `what()` is
* `"feature '<feature>' unavailable: built without <build_flag>"`.
*
* @param feature human-readable feature label (e.g. `"TLS"`, `"WebSocket"`).
* Both views must remain valid for the duration of this
* constructor call; they are consumed before the constructor
* returns and need not outlive it.
* @param build_flag the autoconf-defined `HAVE_*` flag that was off
* in this build (e.g. `"HAVE_GNUTLS"`).
* See @p feature for the lifetime requirement.
*/
feature_unavailable
(std::string_view feature, std::string_view build_flag)
: std::runtime_error([&] {
//
Fixed-text portion: "feature '' unavailable: built without "
//
Computed at compile time to stay in sync with any future wording change.
static
constexpr
std::
size_t
k_fixed_overhead =
std::string_view
(
"
feature '' unavailable: built without
"
).
size
();
std::string msg;
msg.
reserve
(feature.
size
() + build_flag.
size
() + k_fixed_overhead);
msg.
append
(
"
feature '
"
);
msg.
append
(feature);
msg.
append
(
"
' unavailable: built without
"
);
msg.
append
(build_flag);
return
msg;
}()) {}
};
}
//
namespace httpserver
#
endif
//
SRC_HTTPSERVER_FEATURE_UNAVAILABLE_HPP_
Back
|
FazBrowse Home
|
New Git URL