Skip to content

Commit 13c5c6d

Browse files
committed
feat: add the request sdk in dragonfly-client-util
Signed-off-by: chlins <[email protected]>
1 parent 933c8f7 commit 13c5c6d

File tree

6 files changed

+1523
-4
lines changed

6 files changed

+1523
-4
lines changed

Cargo.lock

Lines changed: 126 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dragonfly-client-util/Cargo.toml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ edition.workspace = true
1212
[dependencies]
1313
dragonfly-client-core.workspace = true
1414
dragonfly-api.workspace = true
15-
reqwest.workspace = true
1615
http-range-header.workspace = true
1716
http.workspace = true
1817
tracing.workspace = true
@@ -31,9 +30,25 @@ lazy_static.workspace = true
3130
bytesize.workspace = true
3231
lru.workspace = true
3332
tokio.workspace = true
33+
tokio-util.workspace = true
34+
tonic.workspace = true
35+
reqwest.workspace = true
36+
reqwest-middleware.workspace = true
37+
futures.workspace = true
38+
thiserror.workspace = true
3439
rustix = { version = "1.0.8", features = ["fs"] }
3540
base64 = "0.22.1"
3641
pnet = "0.35.0"
42+
bytes = "1.0.0"
43+
protobuf = "3.7.2"
44+
hashring = "0.3.6"
45+
tonic-health = "0.12.3"
46+
local-ip-address = "0.6.5"
47+
hostname = "^0.4"
48+
dashmap = "6.1.0"
3749

3850
[dev-dependencies]
3951
tempfile.workspace = true
52+
wiremock = "0.6.4"
53+
mockall = "0.13"
54+
mockito = "1.0"

dragonfly-client-util/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ pub mod fs;
1919
pub mod http;
2020
pub mod id_generator;
2121
pub mod net;
22+
pub mod request;
23+
pub mod selector;
2224
pub mod tls;
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright 2025 The Dragonfly Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
use dragonfly_client_core::Error as DFError;
18+
use reqwest;
19+
use std::collections::HashMap;
20+
use tonic::transport::Error as TonicTransportError;
21+
22+
#[derive(Debug, thiserror::Error)]
23+
pub enum Error {
24+
#[error(transparent)]
25+
Base(#[from] DFError),
26+
27+
#[allow(clippy::enum_variant_names)]
28+
#[error(transparent)]
29+
BackendError(#[from] BackendError),
30+
31+
#[allow(clippy::enum_variant_names)]
32+
#[error(transparent)]
33+
ProxyError(#[from] ProxyError),
34+
35+
#[allow(clippy::enum_variant_names)]
36+
#[error(transparent)]
37+
DfdaemonError(#[from] DfdaemonError),
38+
}
39+
40+
impl From<TonicTransportError> for Error {
41+
fn from(err: TonicTransportError) -> Self {
42+
Error::Base(DFError::TonicTransportError(err))
43+
}
44+
}
45+
46+
// BackendError is error detail for Backend.
47+
#[derive(Debug, thiserror::Error)]
48+
#[error("error occurred in the backend server, message: {message:?}, header: {header:?}, status_code: {status_code:?}")]
49+
pub struct BackendError {
50+
// Backend error message.
51+
pub message: Option<String>,
52+
53+
// Backend HTTP response header.
54+
pub header: HashMap<String, String>,
55+
56+
// Backend HTTP status code.
57+
pub status_code: Option<reqwest::StatusCode>,
58+
}
59+
60+
// ProxyError is error detail for Proxy.
61+
#[derive(Debug, thiserror::Error)]
62+
#[error("error occurred in the proxy server, message: {message:?}, header: {header:?}, status_code: {status_code:?}")]
63+
pub struct ProxyError {
64+
// Proxy error message.
65+
pub message: Option<String>,
66+
67+
// Proxy HTTP response header.
68+
pub header: HashMap<String, String>,
69+
70+
// Proxy HTTP status code.
71+
pub status_code: Option<reqwest::StatusCode>,
72+
}
73+
74+
// DfdaemonError is error detail for Dfdaemon.
75+
#[derive(Debug, thiserror::Error)]
76+
#[error("error occurred in the dfdaemon, message: {message:?}")]
77+
pub struct DfdaemonError {
78+
// Dfdaemon error message.
79+
pub message: Option<String>,
80+
}

0 commit comments

Comments
 (0)