mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 10:12:39 +01:00
ircd::server: Add dynamic content allocation after receiving head.
This commit is contained in:
parent
d1b66e2657
commit
c412beacbf
2 changed files with 31 additions and 0 deletions
|
@ -61,6 +61,12 @@ struct ircd::server::in
|
|||
/// received so far. This is only invoked for content, not for the head;
|
||||
/// however the first time it is invoked it is safe to view the in.head
|
||||
std::function<void (const_buffer, const_buffer) noexcept> progress;
|
||||
|
||||
/// The dynamic buffer is a convenience that allows for the content buffer
|
||||
/// to be allocated on demand once the head is received and the length is
|
||||
/// known. To use dynamic, set the content buffer to nothing (i.e default
|
||||
/// constructed mutable_buffer).
|
||||
unique_buffer<mutable_buffer> dynamic;
|
||||
};
|
||||
|
||||
/// This is a handle for being a client to another server. This handle will
|
||||
|
@ -108,6 +114,12 @@ struct ircd::server::request::opts
|
|||
/// received is returned in the value and exceptions are thrown when no
|
||||
/// code can be returned.
|
||||
bool http_exceptions {true};
|
||||
|
||||
/// Only applies when using the dynamic content allocation feature; this
|
||||
/// limits the size of that allocation in case the remote sends a larger
|
||||
/// content-length value. If the remote sends more content, the behavior
|
||||
/// is the same as if specifying an in.content buffer of this size.
|
||||
size_t content_length_maxalloc {256_MiB};
|
||||
};
|
||||
|
||||
inline
|
||||
|
|
|
@ -1944,6 +1944,25 @@ ircd::server::tag::read_head(const const_buffer &buffer,
|
|||
data(beyond_head) + size(partial_content), beyond_content_len
|
||||
};
|
||||
|
||||
// We branch for a feature that allows dynamic allocation of the content
|
||||
// buffer if the user did not specify any buffer.
|
||||
const bool dynamic
|
||||
{
|
||||
null(req.in.content)
|
||||
};
|
||||
|
||||
if(dynamic)
|
||||
{
|
||||
assert(req.opts);
|
||||
const size_t alloc_size
|
||||
{
|
||||
std::min(head.content_length, req.opts->content_length_maxalloc)
|
||||
};
|
||||
|
||||
req.in.dynamic = unique_buffer<mutable_buffer>{alloc_size};
|
||||
req.in.content = req.in.dynamic;
|
||||
}
|
||||
|
||||
// Reduce the user's content buffer to the content-length. This is sort of
|
||||
// how we convey the content-length back to the user. The buffer size will
|
||||
// eventually reflect how much content was actually received; the user can
|
||||
|
|
Loading…
Reference in a new issue