Skip to main content

qubit_http/request/
http_request_body.rs

1/*******************************************************************************
2 *
3 *    Copyright (c) 2025 - 2026.
4 *    Haixing Hu, Qubit Co. Ltd.
5 *
6 *    All rights reserved.
7 *
8 ******************************************************************************/
9//! Request body variants.
10
11use bytes::Bytes;
12use serde::{Deserialize, Serialize};
13use strum::{Display, EnumString};
14
15/// Encodes how the outbound body is represented before sending via reqwest.
16#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize, Display, EnumString)]
17#[serde(rename_all = "snake_case")]
18#[strum(serialize_all = "snake_case")]
19pub enum HttpRequestBody {
20    /// No body (typical for GET/HEAD).
21    #[default]
22    Empty,
23    /// Opaque binary payload.
24    #[strum(disabled)]
25    Bytes(Bytes),
26    /// UTF-8 text; builders may set `Content-Type: text/plain`.
27    #[strum(disabled)]
28    Text(String),
29    /// JSON-serialized bytes; builders may set `Content-Type: application/json`.
30    #[strum(disabled)]
31    Json(Bytes),
32    /// URL-encoded form bytes; builders may set `Content-Type: application/x-www-form-urlencoded`.
33    #[strum(disabled)]
34    Form(Bytes),
35    /// Multipart body bytes; builders may set `Content-Type: multipart/form-data; boundary=...`.
36    #[strum(disabled)]
37    Multipart(Bytes),
38    /// NDJSON bytes (`\n`-delimited JSON objects); builders may set `application/x-ndjson`.
39    #[strum(disabled)]
40    Ndjson(Bytes),
41    /// Chunked upload payload represented as ordered byte chunks.
42    ///
43    /// The client sends this variant through reqwest streaming body support.
44    #[strum(disabled)]
45    Stream(Vec<Bytes>),
46}