Skip to content

Commit 6eb5440

Browse files
committed
Add actix_support and sort dependencies
1 parent 8a2f8db commit 6eb5440

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

Cargo.toml

+8-6
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,19 @@ categories = ["api-bindings"]
1414
[features]
1515
default = []
1616
rocket_support = ["rocket"]
17+
actix_support = ["actix-web"]
1718

1819
[dependencies]
19-
rocket = { version = "0.4", optional = true }
20+
actix-web = { version = "3", optional = true, default-features = false }
21+
base64 = "0.9.2"
22+
bytes = "0.4"
23+
chrono = "0.4"
24+
hmac = "0.6.2"
2025
reqwest = { version = "0.11.0", features = ["blocking", "json"] }
26+
rocket = { version = "0.4", optional = true }
2127
serde = { version = "1.0", features = ["derive"] }
22-
serde_json = "1.0"
2328
serde_derive = "1.0.97"
24-
chrono = "0.4"
25-
bytes = "0.4"
26-
base64 = "0.9.2"
27-
hmac = "0.6.2"
29+
serde_json = "1.0"
2830
sha2 = "0.7.1"
2931

3032
[dev-dependencies]

src/support/actix_support.rs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use actix_web::dev::Payload;
2+
use actix_web::{error::ErrorBadRequest, Error, FromRequest, HttpRequest};
3+
use std::{future::Future, pin::Pin};
4+
5+
#[derive(Debug)]
6+
pub struct Signature {
7+
pub key: String,
8+
}
9+
10+
impl FromRequest for Signature {
11+
type Error = Error;
12+
type Future = Pin<Box<dyn Future<Output = Result<Self, Self::Error>>>>;
13+
type Config = ();
14+
15+
fn from_request(req: &HttpRequest, _payload: &mut Payload) -> Self::Future {
16+
let res = if let Some(x_line_signature) = req.headers().get("x-line-signature") {
17+
if let Ok(key) = x_line_signature.to_str() {
18+
Ok(Signature {
19+
key: key.to_string(),
20+
})
21+
} else {
22+
Err(ErrorBadRequest("x-line-signature is missing"))
23+
}
24+
} else {
25+
Err(ErrorBadRequest("x-line-signature is missing"))
26+
};
27+
Box::pin(async move { res })
28+
}
29+
}

src/support/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
33
#[cfg(feature = "rocket_support")]
44
pub mod rocket_support;
5+
6+
#[cfg(feature = "actix_support")]
7+
pub mod actix_support;

0 commit comments

Comments
 (0)