mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-10-12 15:02:32 +00:00
33 lines
8.9 KiB
HTML
33 lines
8.9 KiB
HTML
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Middleware for limiting total memory usage of concurrent HTTP request bodies."><title>servers::http::memory_limit - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2"href="../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../static.files/rustdoc-1ed95124.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="servers" data-themes="" data-resource-suffix="" data-rustdoc-version="1.98.1 (48a229cea 2026-09-01)" data-channel="1.98.1" data-search-js="search-9944d736.js" data-stringdex-js="stringdex-2da4960a.js" data-settings-js="settings-170eb4bf.js" ><script src="../../../static.files/storage-41dd4d93.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../../static.files/main-417ebf0a.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-f7c3ffd8.css"></noscript><link rel="alternate icon" type="image/png" href="../../../static.files/favicon-32x32-eab170b8.png"><link rel="icon" type="image/svg+xml" href="../../../static.files/favicon-044be391.svg"></head><body class="rustdoc mod"><a class="skip-main-content" href="#main-content">Skip to main content</a><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><rustdoc-topbar><h2><a href="#">Module memory_limit</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../../servers/index.html">servers</a><span class="version">1.4.0-alpha.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module memory_<wbr>limit</a></h2><h3><a href="#structs">Module Items</a></h3><ul class="block"><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#enums" title="Enums">Enums</a></li><li><a href="#functions" title="Functions">Functions</a></li><li><a href="#types" title="Type Aliases">Type Aliases</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="../index.html">In servers::<wbr>http</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><section id="main-content" class="content" tabindex="-1"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../../index.html">servers</a>::<wbr><a href="../index.html">http</a></div><h1>Module <span>memory_<wbr>limit</span> <button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../../src/servers/http/memory_limit.rs.html#15-648">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Middleware for limiting total memory usage of concurrent HTTP request bodies.</p>
|
||
<p>Admission works in two stages:</p>
|
||
<ol>
|
||
<li>Upfront, the request’s <code>Content-Length</code> (if present) is charged to the
|
||
shared <a href="../../request_memory_limiter/struct.ServerMemoryLimiter.html" title="struct servers::request_memory_limiter::ServerMemoryLimiter"><code>ServerMemoryLimiter</code></a>, preserving the configured wait/fail
|
||
policy for regular requests.</li>
|
||
<li>While the body is streamed, <a href="struct.AccountedBody.html" title="struct servers::http::memory_limit::AccountedBody"><code>AccountedBody</code></a> charges every byte beyond
|
||
the upfront reservation. This closes two gaps of a header-only
|
||
reservation: HTTP/1.1 chunked requests carry no <code>Content-Length</code> (and
|
||
would otherwise be admitted for free), and a client can understate the
|
||
header while sending a much larger body.</li>
|
||
</ol>
|
||
<p>Permits acquired while streaming are held by <a href="struct.BodyMemoryAccounting.html" title="struct servers::http::memory_limit::BodyMemoryAccounting"><code>BodyMemoryAccounting</code></a>,
|
||
which is also inserted into the request extensions so they stay alive until
|
||
the whole request is finished (extractors collect the body into owned
|
||
buffers that outlive the body stream itself).</p>
|
||
</div></details><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><dl class="item-table"><dt><a class="struct" href="struct.AccountedBody.html" title="struct servers::http::memory_limit::AccountedBody">Accounted<wbr>Body</a><span title="Restricted Visibility"> 🔒</span> </dt><dd>A request body wrapper that charges the shared limiter for every byte
|
||
streamed beyond <code>pre_charged</code> (the upfront <code>Content-Length</code> reservation).</dd><dt><a class="struct" href="struct.BodyMemoryAccounting.html" title="struct servers::http::memory_limit::BodyMemoryAccounting">Body<wbr>Memory<wbr>Accounting</a><span title="Restricted Visibility"> 🔒</span> </dt><dd>Holds the memory guards acquired while a request body is streamed. Shared
|
||
between the <a href="struct.AccountedBody.html" title="struct servers::http::memory_limit::AccountedBody"><code>AccountedBody</code></a> wrapper, the request extensions and the
|
||
middleware itself, so the permits are only released when the request
|
||
(including any collected body buffers and the handler still using them)
|
||
is finished.</dd><dt><a class="struct" href="struct.ContentEncoded.html" title="struct servers::http::memory_limit::ContentEncoded">Content<wbr>Encoded</a><span title="Restricted Visibility"> 🔒</span> </dt><dd>Marker inserted by <a href="fn.memory_limit_middleware.html" title="fn servers::http::memory_limit::memory_limit_middleware"><code>memory_limit_middleware</code></a> when the request arrives
|
||
with a non-identity <code>Content-Encoding</code> header. Route-local
|
||
<a href="../fn.decoded_body_accounting_middleware.html" title="fn servers::http::decoded_body_accounting_middleware"><code>decoded_body_accounting_middleware</code></a> uses it to account the decompressed
|
||
body: only such requests expand during request decompression.</dd></dl><h2 id="enums" class="section-header">Enums<a href="#enums" class="anchor">§</a></h2><dl class="item-table"><dt><a class="enum" href="enum.ChargeOutcome.html" title="enum servers::http::memory_limit::ChargeOutcome">Charge<wbr>Outcome</a><span title="Restricted Visibility"> 🔒</span> </dt></dl><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><dl class="item-table"><dt><a class="fn" href="fn.decoded_body_accounting_middleware.html" title="fn servers::http::memory_limit::decoded_body_accounting_middleware">decoded_<wbr>body_<wbr>accounting_<wbr>middleware</a></dt><dd>Route-local accounting for routes that install <code>RequestDecompressionLayer</code>:
|
||
it must be layered <em>inside</em> the
|
||
decompression layer, so the body it wraps is the <strong>decompressed</strong> stream.
|
||
It requires the global accounting installed by <a href="../struct.HttpServer.html" title="struct servers::http::HttpServer"><code>crate::http::HttpServer</code></a>
|
||
and must use the same <a href="../../request_memory_limiter/struct.ServerMemoryLimiter.html" title="struct servers::request_memory_limiter::ServerMemoryLimiter"><code>ServerMemoryLimiter</code></a>.</dd><dt><a class="fn" href="fn.limit_exceeded_error.html" title="fn servers::http::memory_limit::limit_exceeded_error">limit_<wbr>exceeded_<wbr>error</a><span title="Restricted Visibility"> 🔒</span> </dt><dt><a class="fn" href="fn.memory_limit_middleware.html" title="fn servers::http::memory_limit::memory_limit_middleware">memory_<wbr>limit_<wbr>middleware</a></dt><dt><a class="fn" href="fn.quota_exceeded_response.html" title="fn servers::http::memory_limit::quota_exceeded_response">quota_<wbr>exceeded_<wbr>response</a><span title="Restricted Visibility"> 🔒</span> </dt><dd>Rewrites the response of a request whose body accounting hit the quota:
|
||
the failure aborts the body mid-stream, so the extractors reject the
|
||
request with a generic body error (mapped to 400). Quota exhaustion must
|
||
surface as 429, matching the upfront admission path, so clients can tell
|
||
backpressure apart from malformed input.</dd></dl><h2 id="types" class="section-header">Type Aliases<a href="#types" class="anchor">§</a></h2><dl class="item-table"><dt><a class="type" href="type.AcquireFuture.html" title="type servers::http::memory_limit::AcquireFuture">Acquire<wbr>Future</a><span title="Restricted Visibility"> 🔒</span> </dt></dl></section></div></main></body></html> |