Skip to content

Commit 453202b

Browse files
committed
feat: add the request sdk in dragonfly-client-util
Signed-off-by: chlins <[email protected]>
1 parent 8ff694f commit 453202b

File tree

7 files changed

+1549
-20
lines changed

7 files changed

+1549
-20
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ members = [
1212
]
1313

1414
[workspace.package]
15-
version = "1.0.18"
15+
version = "1.0.19"
1616
authors = ["The Dragonfly Developers"]
1717
homepage = "https://d7y.io/"
1818
repository = "https://github.com/dragonflyoss/client.git"
@@ -22,13 +22,13 @@ readme = "README.md"
2222
edition = "2021"
2323

2424
[workspace.dependencies]
25-
dragonfly-client = { path = "dragonfly-client", version = "1.0.18" }
26-
dragonfly-client-core = { path = "dragonfly-client-core", version = "1.0.18" }
27-
dragonfly-client-config = { path = "dragonfly-client-config", version = "1.0.18" }
28-
dragonfly-client-storage = { path = "dragonfly-client-storage", version = "1.0.18" }
29-
dragonfly-client-backend = { path = "dragonfly-client-backend", version = "1.0.18" }
30-
dragonfly-client-util = { path = "dragonfly-client-util", version = "1.0.18" }
31-
dragonfly-client-init = { path = "dragonfly-client-init", version = "1.0.18" }
25+
dragonfly-client = { path = "dragonfly-client", version = "1.0.19" }
26+
dragonfly-client-core = { path = "dragonfly-client-core", version = "1.0.19" }
27+
dragonfly-client-config = { path = "dragonfly-client-config", version = "1.0.19" }
28+
dragonfly-client-storage = { path = "dragonfly-client-storage", version = "1.0.19" }
29+
dragonfly-client-backend = { path = "dragonfly-client-backend", version = "1.0.19" }
30+
dragonfly-client-util = { path = "dragonfly-client-util", version = "1.0.19" }
31+
dragonfly-client-init = { path = "dragonfly-client-init", version = "1.0.19" }
3232
dragonfly-api = "=2.1.62"
3333
thiserror = "2.0"
3434
futures = "0.3.31"

dragonfly-client-util/Cargo.toml

Lines changed: 15 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,24 @@ 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+
mockito = "1.0"
53+
mocktail = "0.3.0"

dragonfly-client-util/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ pub mod http;
2020
pub mod id_generator;
2121
pub mod net;
2222
pub mod shutdown;
23+
pub mod request;
24+
pub mod selector;
2325
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)