You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TASK-029: collapse IP-control and stop verbs to canonical names
Public API rename (no aliases, per v2.0 breaking-changes policy):
- webserver::sweet_kill -> webserver::stop_and_wait
- webserver::ban_ip / unban_ip / allow_ip / disallow_ip
collapsed to webserver::block_ip(std::string_view) /
webserver::unblock_ip(std::string_view)
Per PRD-NAM-REQ-005 and OQ-004 the public surface keeps only deny-list
manipulation. The internal allowances set and the is_allowed branch in
policy_callback remain in place so default_policy(REJECT) keeps working
at the daemon level, but they are no longer reachable from the public
API. Coverage note: five ban_system tests that drove the allow-list
through the (now-removed) public API are deleted; a follow-up unit
test that pokes the PIMPL could restore that coverage at the cost of
breaking the PIMPL boundary, which is deliberately out of scope here.
webserver::stop() is unchanged ("stop without waiting" verb).
shoutCAST is preserved per OQ-005.
Action items:
- src/httpserver/webserver.hpp: new <string_view> include; old four
ban/allow declarations replaced with block_ip / unblock_ip; new
doxygen; sweet_kill renamed to stop_and_wait.
- src/webserver.cpp: stop_and_wait body unchanged; block_ip /
unblock_ip materialize std::string once at the boundary to call
ip_representation(const std::string&) (no string_view ctor added
to ip_representation).
- test/integ/ws_start_stop.cpp: sweet_kill test renamed.
- test/integ/ban_system.cpp: 4 retained tests renamed inline; 5
allow_ip/disallow_ip tests removed.
- examples/minimal_ip_ban.cpp: rewritten to demonstrate block_ip
under the default ACCEPT policy.
- examples/daemon_info.cpp: sweet_kill -> stop_and_wait.
- README.md: bullets + code samples updated.
Acceptance criteria verified:
- grep '\\bsweet_kill\\b' src/httpserver/*.hpp src/*.cpp -> empty
- grep '\\b(ban_ip|unban_ip|allow_ip|disallow_ip)\\b'
src/httpserver/*.hpp -> empty
- camelCase grep on src/httpserver/*.hpp returns pre-existing
matches only (comments, MHD/GnuTLS types, generateFilenameException,
shoutCAST). No method names introduced or touched by this task
use camelCase.
- make check (release + --enable-debug): 40/40 pass.
- cpplint: clean on all touched files.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: README.md
+8-9Lines changed: 8 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -544,7 +544,7 @@ Once a webserver is created, you can manage its execution through the following
544
544
*_**void** webserver::start(**bool** blocking):_ Allows to start a server. If the `blocking` flag is passed as `true`, it will block the execution of the current thread until a call to stop on the same webserver object is performed.
545
545
*_**void** webserver::stop():_ Allows to stop a server. It immediately stops it.
546
546
*_**bool** webserver::is_running():_ Checks if a server is running
547
-
*_**void** webserver::sweet_kill():_Allows to stop a server. It doesn't guarantee an immediate halt to allow for thread termination and connection closure.
547
+
*_**void** webserver::stop_and_wait():_Stop the webserver and wait for in-flight handlers to complete before returning. Use `stop()` when no such guarantee is required.
548
548
*_**int** webserver::quiesce():_ Quiesce the daemon: stop accepting new connections while letting in-flight requests complete. Returns the listen socket file descriptor (the caller can close it), or `-1` on error.
549
549
*_**bool** webserver::run():_ Run the webserver's event loop once (non-blocking). For use with external event loops when the server is started without internal threading. Returns `true` on success.
550
550
*_**bool** webserver::run_wait(**int32_t** millisec):_ Run the webserver's event loop, blocking until there is activity or the timeout expires. Pass `-1` for indefinite wait. Returns `true` on success.
@@ -946,10 +946,8 @@ libhttpserver provides natively a system to blacklist and whitelist IP addresses
946
946
The system supports both IPV4 and IPV6 and manages them transparently. The only requirement is for ipv6 to be enabled on your server - you'll have to enable this by using the `use_ipv6` method on `create_webserver`.
947
947
948
948
You can explicitly ban or allow an IP address using the following methods on the `webserver` class:
949
-
* _**void** ban_ip(**const std::string&** ip):_ Adds one IP (or a range of IPs) to the list of the banned ones. Takes in input a `string` that contains the IP (or range of IPs) to ban. To use when the `default_policy` is `ACCEPT`.
950
-
* _**void** allow_ip(**const std::string&** ip):_ Adds one IP (or a range of IPs) to the list of the allowed ones. Takes in input a `string` that contains the IP (or range of IPs) to allow. To use when the `default_policy` is `REJECT`.
951
-
* _**void** unban_ip(**const std::string&** ip):_ Removes one IP (or a range of IPs) from the list of the banned ones. Takes in input a `string` that contains the IP (or range of IPs) to remove from the list. To use when the `default_policy` is `ACCEPT`.
952
-
* _**void** disallow_ip(**const std::string&** ip):_ Removes one IP (or a range of IPs) from the list of the allowed ones. Takes in input a `string` that contains the IP (or range of IPs) to remove from the list. To use when the `default_policy` is `REJECT`.
949
+
* _**void** block_ip(**std::string_view** ip):_ Add one IP (or a range, e.g. `"127.0.0.*"`) to the block list. Connections from a matching address are refused at the policy callback. Intended for use under the default `ACCEPT` policy.
950
+
* _**void** unblock_ip(**std::string_view** ip):_ Remove one IP (or a range) from the block list. Idempotent: removing an entry that is not currently blocked is a no-op.
953
951
954
952
### IP String Format
955
953
The IP string format can represent both IPV4 and IPV6. Addresses will be normalized by the webserver to operate in the same sapce. Any valid IPV4 or IPV6 textual representation works.
@@ -977,10 +975,11 @@ Examples of valid IPs include:
977
975
};
978
976
979
977
int main(int argc, char** argv) {
980
-
webserver ws = create_webserver(8080)
981
-
.default_policy(http::http_utils::REJECT);
978
+
webserver ws = create_webserver(8080);
982
979
983
-
ws.allow_ip("127.0.0.1");
980
+
// Refuse connections from this address; everything else is accepted
981
+
// by default. Use a range like "127.0.0.*" to block a wildcard.
982
+
ws.block_ip("10.0.0.1");
984
983
985
984
hello_world_resource hwr;
986
985
ws.register_resource("/hello", &hwr);
@@ -1728,7 +1727,7 @@ You can also check this example on [github](https://github.com/etr/libhttpserver
0 commit comments