Skip to main content

qubit_http/request/
http_request_body.rs

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