struct request_part_t Fields
name | std::string_view | The name its Content-Disposition gives. |
|---|---|---|
content_type | std::string_view | Its Content-Type, empty when absent. |
data | std::string_view | Its payload, undecoded. |
Ask your coding agent about this page, or add the docs server to it
curl -s 'https://www.unum.cloud/docs/ucall/cpp/requests.md' | claude -p "How would this fit my code?"A handler receives each request_t by value, owning it.
Its reads view the received bytes: verb, path, query_string, path_parameter, query, header and body, with peer naming the interface it arrived on, the client’s authenticated Noise key and its socket address.
Every read that can fail answers an expected, so a missing header answers status_code_t::not_found_k and a body read on a streamed route status_code_t::invalid_argument_k, while the counts answer plain numbers.
The path and query values stay percent-encoded as sent, which uc::decode_percent decodes, header names match case-insensitively, and the body arrives whole, decoded from chunked framing if it was sent that way. fields_count and field read every header field in arrival order, names lowercased and values trimmed, as a proxy forwards a head. path_segments_count and path_segment read the path component by component, and parts_count and part read a multipart/form-data body as request_part_ts.
void order(uc::request_t request) noexcept {
auto [token, token_status] = request.header("authorization");
if (token_status.failed()) {
[[maybe_unused]] uc::status_t const refused =
std::move(request).reply_error(ucall_http_status_unauthorized_k, "sign in first");
return;
}
auto [order_id, order_status] = request.path_parameter("order");
ucall_bytes_view_t const headers[] {uc::bytes_view("content-type: text/plain"),
uc::bytes_view("cache-control: no-store")};
ucall_reply_part_t const parts[] {uc::bytes_part(order_id), uc::bytes_part(" by "), uc::bytes_part(token)};
uc::deferred<> sent;
[[maybe_unused]] uc::status_t const replied =
std::move(request).reply_parts(ucall_http_status_created_k, headers, parts, sent);
}reply, reply_error, reply_parts and reply_stream take the request, spelled std::move(request).reply(...), and Content-Length, Date and Server are generated.
A reply copies the bytes it sends before it returns, so a body made of the request’s bytes needs no copy of its own.
A request moves to any thread, so a handler may hand it to a worker and return, and the worker replies whenever it is done.
A request destroyed without a reply answers 500.
The library clears the request’s handle once a reply took it, a closed connection included, which reports status_code_t::connection_closed_k; a reply it refused keeps the handle, and destroying the request then answers 500.
request_part_tOne part of a multipart/form-data request body, viewing the received bytes.struct request_part_t name | std::string_view | The name its Content-Disposition gives. |
|---|---|---|
content_type | std::string_view | Its Content-Type, empty when absent. |
data | std::string_view | Its payload, undecoded. |
peer_tWho sent a request: the interface it arrived on, the client's authenticated static key, zeroed in plaintext, and its socket address.struct peer_t network_interface_index | std::size_t | The position of the interface among those the server answers on. |
|---|---|---|
static_key | ucall_noise_key_t | The client's authenticated Noise static key, zeroed on plaintext interfaces. |
address | ucall_peer_address_t | The client's socket address as accepted. |
string_view >The bytes a call wrote into a counted view, read back as text once the call is final.template <>
struct string_view > value | ucall_bytes_view_t | The view the call writes in place. |
|---|
field_tOne header field line, its name lowercased and its value trimmed.struct field_t name | std::string_view | The field name, lowercased as the parser keeps it. |
|---|---|---|
value | std::string_view | The field value, without surrounding whitespace. |
deferredA submitted call: its outcome and its outputs, owned until the call is final, while the receiver, inputs, arena and handlers it was handed stay allocated and unchanged until then.7template <typename value_type_ = void>
class deferred answer_typeWhat wait answers: what the blocking call would have.using answer_type = std::conditional_t<std::is_void_v<value_type_>, status_t, expected<value_type_>>; deferredAn empty slot, final from the start, which resubmit fills.deferred() noexcept=default; template <typename submit_type_>
requires std::invocable<submit_type_ const&, ucall_outcome_t*, outputs<value_type_>*>
deferred(submit_type_ const & submit) noexcept; Runs submit with this call's outcome and outputs, where the library reports.
deferred(status_t status) noexcept; A call refused before it crossed, final from the start.
deferred(deferred const &)=delete; resubmitWaits only while the slot's previous call still runs, then runs submit in its place.template <typename submit_type_>
requires std::invocable<submit_type_ const&, ucall_outcome_t*, outputs<value_type_>*>
void resubmit(submit_type_ const & submit) noexcept; operator=deferred & operator=(deferred const &)=delete; ~deferred~deferred() noexcept; statusstatus_code_t::deferred_k until the call is final, then its final status, polled without blocking.status_code_t status() noexcept; waitBlocks until the call is final and answers what a blocking call would have.answer_type wait() noexcept; template <a_scheduler scheduler_type_>
awaiter<value_type_, scheduler_type_> wait(
scheduler_type_ & loop) noexcept; Awaits the call on loop, which polls its status until it is final.
request_tA received request, owned by one thread at a time, answered at most once.22class request_t Reads view the received bytes until the reply. A reply takes the request, as in std::move(request).reply(...), and a request destroyed without one answers 500. A reply the library refused leaves the request retained, answering 500 once destroyed.
request_trequest_t() noexcept=default; request_t(
ucall_server_t server,
ucall_received_http_request_t request) noexcept; request_t(request_t && other) noexcept; request_t(request_t const &)=delete; operator=request_t & operator=(request_t && other) noexcept; request_t & operator=(request_t const &)=delete; ~request_t~request_t() noexcept; verbThe HTTP method, which tells apart the requests of an endpoint taking any verb.ucall_verb_t verb() const noexcept; pathThe path as sent, still percent-encoded, without the query.expected<std::string_view> path() const noexcept; query_stringThe query after the first '?expected<std::string_view> query_string() const noexcept; ', still percent-encoded, or empty without one.
bodyThe body, decoded from chunked framing if it arrived that way; a streamed endpoint refuses it, as body_chunk pulls its body.expected<std::string_view> body() const noexcept; path_parameterThe value the endpoint's template captured under name, case-sensitive.expected<std::string_view> path_parameter(
std::string_view name) const noexcept; queryThe value of query parameter name, case-sensitive and still percent-encoded.expected<std::string_view> query(std::string_view name) const noexcept; headerThe value of header name, matched case-insensitively.expected<std::string_view> header(std::string_view name) const noexcept; fields_countHeader field lines, repeated names apart.std::size_t fields_count() const noexcept; fieldHeader field line index in arrival order.expected<field_t> field(std::size_t index) const noexcept; path_segments_countPath components, as sent and still percent-encoded.std::size_t path_segments_count() const noexcept; path_segmentPath component index, counting from zero.expected<std::string_view> path_segment(
std::size_t index) const noexcept; parts_countParts of a multipart/form-data body, zero for any other body.std::size_t parts_count() const noexcept; partPart index of a multipart/form-data body, its payload undecoded.expected<request_part_t> part(std::size_t index) const noexcept; peerThe interface the request arrived on, the client's key and its address, readable after its connection closed.expected<peer_t> peer() const noexcept; body_chunkPulls the body bytes decoded since the last pull into into, empty once the body ended and valid until the next pull or the reply; answers a refusal, or success while the pull runs.status_t body_chunk(deferred<std::string_view> & into) noexcept; On a streamed endpoint the pull is final once the bytes arrive, which the polling thread delivers; a pull from the polling thread itself finding nothing answers status_code_t::would_block_k instead. On a buffered one the first pull is the whole body. The slot waits for its previous call first, if that still runs.
replyReplies with http_status, full header lines like "content-type: text/plain", and body, generating the length, date and server lines.status_t reply(
ucall_http_status_t http_status,
std::span<ucall_bytes_view_t const> headers,
std::string_view body) &&noexcept; reply_errorReplies with an error http_status, 400 or above, and a plain-text message.status_t reply_error(
ucall_http_status_t http_status,
std::string_view message) &&noexcept; reply_partsReplies with http_status, header lines and parts concatenated into the body, its length measured from the files.status_t reply_parts(
ucall_http_status_t http_status,
std::span<ucall_bytes_view_t const> headers,
std::span<ucall_reply_part_t const> parts,
deferred<> & into) &&noexcept; Final on return for bytes alone; with a file or path part the caller's slot into stays deferred until every part is sent, which the polling thread does, so await it there or wait elsewhere. Answers a refusal, or success while the parts send. A part failing before the head left replaces the reply with 404, 416 or 500, reported as a status. The slot waits for its previous call first, if that still runs.
reply_streamSends the status line and header lines and opens a body appended part by part: chunked, or of the length a Content-Length line declares; a closed connection ends the reply here.expected<reply_stream_t> reply_stream(
ucall_http_status_t http_status,
std::span<ucall_bytes_view_t const> headers) &&noexcept; bytes_partA reply part of bytes in memory, copied before the reply returns.ucall_reply_part_t bytes_part(std::string_view bytes) noexcept; bytes_viewViews text as the counted bytes every verb reads, without a copy.ucall_bytes_view_t bytes_view(std::string_view text) noexcept; decode_percentDecodes the percent escapes of encoded into decoded, which may alias it, and a '+' as a space in a query, answering the decoded prefix of decoded.expected<std::string_view> decode_percent(
std::string_view encoded,
std::span<char> decoded,
ucall_percent_mode_t mode) noexcept; is_deferredWhether answer_type_ is a call the caller holds rather than a final answer.bool is_deferred;