couchbase_core/httpx/
request.rs1use bytes::Bytes;
20use serde::Serialize;
21use std::collections::HashMap;
22
23#[derive(Debug)]
24#[non_exhaustive]
25pub struct Request {
26 pub(crate) method: http::Method,
27 pub(crate) uri: String,
28 pub(crate) auth: Option<Auth>,
29 pub(crate) user_agent: Option<String>,
30 pub(crate) content_type: Option<String>,
31 pub(crate) body: Option<Bytes>,
32 pub(crate) headers: HashMap<String, String>,
33 pub(crate) unique_id: Option<String>,
34}
35
36impl Request {
37 pub fn new(method: http::Method, uri: impl Into<String>) -> Self {
38 Self {
39 method,
40 uri: uri.into(),
41 auth: None,
42 user_agent: None,
43 content_type: None,
44 body: None,
45 headers: HashMap::new(),
46 unique_id: None,
47 }
48 }
49
50 pub fn auth(mut self, auth: impl Into<Option<Auth>>) -> Self {
51 self.auth = auth.into();
52 self
53 }
54
55 pub fn user_agent(mut self, user_agent: impl Into<Option<String>>) -> Self {
56 self.user_agent = user_agent.into();
57 self
58 }
59
60 pub fn content_type(mut self, content_type: impl Into<Option<String>>) -> Self {
61 self.content_type = content_type.into();
62 self
63 }
64
65 pub fn body(mut self, body: impl Into<Option<Bytes>>) -> Self {
66 self.body = body.into();
67 self
68 }
69
70 pub fn unique_id(mut self, unique_id: impl Into<Option<String>>) -> Self {
71 self.unique_id = unique_id.into();
72 self
73 }
74
75 pub fn add_header(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
76 self.headers.insert(key.into(), value.into());
77 self
78 }
79}
80
81#[derive(PartialEq, Eq, Debug, Clone)]
82pub struct BasicAuth {
83 pub(crate) username: String,
84 pub(crate) password: String,
85}
86
87impl BasicAuth {
88 pub fn new(username: impl Into<String>, password: impl Into<String>) -> Self {
89 Self {
90 username: username.into(),
91 password: password.into(),
92 }
93 }
94}
95
96#[derive(PartialEq, Eq, Debug)]
97#[non_exhaustive]
98pub enum Auth {
99 BasicAuth(BasicAuth),
100 OnBehalfOf(OnBehalfOfInfo),
101}
102
103#[derive(Clone, PartialEq, Eq, Debug, Serialize)]
104#[non_exhaustive]
105pub struct OnBehalfOfInfo {
106 pub(crate) username: String,
107 pub(crate) password_or_domain: OboPasswordOrDomain,
108}
109
110impl OnBehalfOfInfo {
111 pub fn new(username: impl Into<String>, password_or_domain: OboPasswordOrDomain) -> Self {
112 Self {
113 username: username.into(),
114 password_or_domain,
115 }
116 }
117}
118
119#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
120pub enum OboPasswordOrDomain {
121 Password(String),
122 Domain(String),
123}