Net: configurable body limit, opt-in redirect following, tolerant CONNECT

HttpClient could not download release artifacts (e.g. yt-dlp self-update):

- Beast's default body limit (~1 MiB) rejected the ~30 MB binary with
  "body limit exceeded". Add set_max_body_size() (0 = unlimited; default
  64 MiB) and read the body through a response_parser with that limit.
- Through an HTTP proxy the CONNECT reply was parsed with empty_body, so any
  body on a non-2xx reply threw "unexpected body" before the status could be
  inspected. Read only the header (skip(true) + read_header) so the tunnel
  status is checked cleanly.
- Add set_max_redirects() to follow 3xx Location transparently (default 0 =
  off, so callers that inspect redirects keep working). Resolves absolute,
  host-relative and bare-relative Location targets.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Opus 4.8 committed 2026-06-25 01:53:10 +03:00
1 parent 2c3ff56b67
commit 96b8b19970
2 files changed
+136 -65

No files matched your search

+15
View File
@@ -87,6 +87,19 @@ namespace Void::Net
/// scraping/proxy use; enable for security-sensitive callers).
void set_verify_tls(bool on) noexcept { m_verify_tls = on; }
/// Maximum response body size in bytes. 0 means unlimited. Default
/// is 64 MiB (Beast's own default of ~1 MiB is too small for binary
/// downloads such as release artifacts). Raise for large downloads.
void set_max_body_size(std::uint64_t bytes) noexcept
{
m_max_body = bytes;
}
/// Follow up to `n` HTTP 3xx redirects transparently (default 0 =
/// do not follow; the caller sees the 3xx response and its Location
/// header). Opt-in so callers that inspect redirects keep working.
void set_max_redirects(int n) noexcept { m_max_redirects = n; }
/// Execute a request. A per-request `Request::proxy` is not modelled;
/// the client-level proxy applies. Returns an Error only on transport
/// failure — a non-2xx HTTP response is a successful Result.
@@ -106,6 +119,8 @@ namespace Void::Net
ProxyConfig m_proxy{};
std::string m_user_agent = "Void.Net/1.0";
bool m_verify_tls = false;
std::uint64_t m_max_body = 64ull * 1024 * 1024;
int m_max_redirects = 0;
};
} // namespace Void::Net