Archived
vendor: cpp-httplib v0.46.1 -> v0.64.0 -- the drain patch retires to one line
Eighteen upstream releases, taken the way the lift was taken: the split pair llama.cpp now carries (1ab23c33b), against the cpp-httplib v0.64.0 tag. The vendored pair before this commit was byte-identical to the old base plus patch 0022 -- re-checked against the pinned lift commit, not taken on faith. 0022 was written because upstream's keep-alive drain could be paced one byte per socket timeout forever, and because a refused request's unread body had no reason to be drained at all. v0.64.0 does both of those itself: every 4xx/5xx response now carries Connection: close, a scope_exit in write_response closes the socket when it sees that option, the drain is skipped for any response committed to close, and a drain that does run is bounded by a 256 KB cap, the connection's read timeout as a total, and an immediate close for a part-read body. The old patch applied nowhere, and mostly needed to be nothing. What one line is still owed: the library bounds the drain's time only by the connection's read timeout -- the same knob that bounds a whole request's reads, uploads included, so lowering it would cap uploads too. The reworked patch gives the drain a five-second budget of its own. transport_test's cases for the refusal and the stalled drain are unchanged: they pin the behavior, whoever in the tree implements it. Also new in this window and watched with interest: set_trusted_proxies arrives with real IP matching -- the seam a coming commit wires. Manifest regenerated; vendor_sums green.
This commit is contained in:
1 parent
3decb3ca13
commit
40e1b3073b
7 files changed
+6311
-2472
No files matched your search
Vendored
-58
@@ -1,58 +0,0 @@
|
||||
diff --git a/httplib.cpp b/httplib.cpp
|
||||
index b9d05d9..fe98b5f 100644
|
||||
--- a/httplib.cpp
|
||||
+++ b/httplib.cpp
|
||||
@@ -8453,6 +8453,20 @@ Server::process_request(Stream &strm, const std::string &remote_addr,
|
||||
: StatusCode::PartialContent_206;
|
||||
}
|
||||
|
||||
+ // LOCAL CHANGE (radiance): a request the API-key gate refused (401
|
||||
+ // answered before any handler saw it) has no further use for this
|
||||
+ // connection, and must not keep one: its unread body would otherwise be
|
||||
+ // drained on the keep-alive socket, which hands the refusing client a
|
||||
+ // way to pace this worker — one byte per socket timeout, indefinitely.
|
||||
+ // Say close on the response itself and end the connection; the unread
|
||||
+ // bytes die with it, which is also what makes the drain below moot for
|
||||
+ // the refusal.
|
||||
+ if (res.status == StatusCode::Unauthorized_401 && !req.body_consumed_ &&
|
||||
+ detail::has_framed_body(req)) {
|
||||
+ close_connection = true;
|
||||
+ connection_closed = true;
|
||||
+ }
|
||||
+
|
||||
// Serve file content by using a content provider
|
||||
auto file_open_error = false;
|
||||
if (!res.file_content_path_.empty()) {
|
||||
@@ -8499,14 +8513,30 @@ Server::process_request(Stream &strm, const std::string &remote_addr,
|
||||
|
||||
// Drain any unconsumed framed body to prevent request smuggling on
|
||||
// keep-alive. Without framing there is no body to drain — reading would
|
||||
- // consume the next request (issue #2450).
|
||||
+ // consume the next request (issue #2450). A 401 refusal never gets here
|
||||
+ // with a live connection (see the LOCAL CHANGE above).
|
||||
+ //
|
||||
+ // LOCAL CHANGE (radiance): the drain is bounded by a deadline, twice
|
||||
+ // over — per packet gap (the stream's read wait shortened to 5 s for the
|
||||
+ // drain: the connection's own 30 s bounds a gap, not the drain, and a
|
||||
+ // client dribbling one byte per timeout would pace this worker
|
||||
+ // indefinitely) and in total (the provider stops once 5 s have passed).
|
||||
+ // Past either, the connection is closed and the unread bytes die with it.
|
||||
if (!req.body_consumed_ && detail::has_framed_body(req)) {
|
||||
+ constexpr time_t kDrainBudgetSec = 5;
|
||||
+ strm.set_read_timeout(kDrainBudgetSec, 0);
|
||||
+ const auto drain_until = std::chrono::steady_clock::now() +
|
||||
+ std::chrono::seconds(kDrainBudgetSec);
|
||||
int dummy_status;
|
||||
if (!detail::read_content(
|
||||
strm, req, payload_max_length_, dummy_status, nullptr,
|
||||
- [](const char *, size_t, size_t, size_t) { return true; }, false)) {
|
||||
+ [drain_until](const char *, size_t, size_t, size_t) {
|
||||
+ return std::chrono::steady_clock::now() < drain_until;
|
||||
+ },
|
||||
+ false)) {
|
||||
connection_closed = true;
|
||||
}
|
||||
+ strm.set_read_timeout(read_timeout_sec_, read_timeout_usec_);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -0,0 +1,22 @@
|
||||
diff --git a/httplib.cpp b/httplib.cpp
|
||||
index ebe01d1..e5efe4d 100644
|
||||
--- a/httplib.cpp
|
||||
+++ b/httplib.cpp
|
||||
@@ -10585,7 +10585,16 @@ Server::process_request(Stream &strm, const std::string &remote_addr,
|
||||
// arrive within the read timeout.
|
||||
if (!req.body_consumed_ && detail::has_framed_body(req) &&
|
||||
!detail::has_header_token(res.headers, "Connection", "close")) {
|
||||
- strm.set_max_timeout(read_timeout_msec);
|
||||
+ // LOCAL CHANGE (radiance): the drain's budget is the lesser of five
|
||||
+ // seconds and the connection's read timeout. read_timeout_msec bounds a
|
||||
+ // whole request's reads -- uploads included -- so it cannot itself be
|
||||
+ // lowered to hurry a drain along; without its own budget, a client
|
||||
+ // dribbling one byte per gap paces this worker for the connection's
|
||||
+ // full timeout after the response was already sent.
|
||||
+ constexpr int kDrainBudgetMsec = 5000;
|
||||
+ strm.set_max_timeout(read_timeout_msec < kDrainBudgetMsec
|
||||
+ ? read_timeout_msec
|
||||
+ : kDrainBudgetMsec);
|
||||
int dummy_status;
|
||||
if (req.body_read_started_ ||
|
||||
!detail::read_content(
|
||||
Reference in new issue
Block a user