Skip to content

Commit 6a3c93f

Browse files
committed
refactor: simplify types api
1 parent 4cdfa1d commit 6a3c93f

File tree

8 files changed

+49
-337
lines changed

8 files changed

+49
-337
lines changed

Cargo.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
[package]
22
name = "hyper-middleware"
3-
description = "A compact middleware and handler system for Hyper inspired by The Iron Framework."
3+
description = "A compact HTTP middleware and handler system for Hyper 0.14"
44
version = "0.0.0"
55
authors = ["Jose Quintana <https://joseluisq.net>"]
66
license = "MIT OR Apache-2.0"
77
repository = "https://github.com/static-web-server/hyper-middleware"
8-
documentation = "https://docs.rs/unzpack"
8+
documentation = "https://docs.rs/hyper-middleware"
99
edition = "2018"
1010
categories = ["network-programming", "web-programming::http-server"]
1111
include = [
12-
"src/**/*",
12+
"src/**/*.rs",
1313
"Cargo.toml",
14+
"README.md",
1415
"LICENSE-MIT",
1516
"LICENSE-APACHE"
1617
]
@@ -20,12 +21,12 @@ keywords = [
2021
"hyper-rs",
2122
"middleware",
2223
"service",
24+
"http-middleware",
2325
]
2426

2527
[dependencies]
2628
hyper = { version = "0.14", default-features = false, features = ["server", "tcp"] }
2729
anyhow = "1.0"
28-
thiserror = "1.0"
2930

3031
[dev-dependencies]
3132
hyper = { version = "0.14", features = ["tcp", "server", "http1"] }

README.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
# Hyper Middleware (WIP)
1+
# Hyper Middleware
22

3-
> A compact middleware and handler system for [Hyper](https://github.com/hyperium/hyper) `0.14.x`.
3+
[![hyper-middleware crate](https://img.shields.io/crates/v/hyper-middleware.svg)](https://crates.io/crates/hyper-middleware)
4+
[![Released API docs](https://docs.rs/hyper-middleware/badge.svg)](https://docs.rs/hyper-middleware)
5+
[![hyper-middleware crate license](https://img.shields.io/crates/l/hyper-middleware)](./LICENSE-MIT)
6+
7+
> A compact HTTP middleware and handler system for [Hyper](https://github.com/hyperium/hyper) `0.14.x`.<br>
8+
> **NOTE:** This crate is still under active development.
49
510
## Features
611

712
- Compact Middleware and Handler System inspired by [The Iron Framework](https://github.com/iron/iron).
8-
- Simple Hyper Service with convenient __Remote Address__ access.
9-
- Error and return types powered by [anyhow](https://github.com/dtolnay/anyhow).
13+
- Simple [Hyper Service](https://docs.rs/hyper/latest/hyper/service/trait.Service.html) with convenient __Remote Address__ access.
14+
- Convenient `Error` and `Result` types powered by [anyhow](https://github.com/dtolnay/anyhow).
1015

1116
## Example
1217

@@ -34,7 +39,7 @@ struct Application {
3439
impl Handler for Application {
3540
fn handle(&self, req: &mut Request) -> Result<Response> {
3641
// Access the Hyper incoming Request
37-
println!("URI Path: {}", req.uri().path());
42+
println!("Handler - URI Path: {}", req.uri().path());
3843

3944
// Access the custom app options
4045
println!("Config Root: {}", self.opts.root.display());
@@ -45,24 +50,24 @@ impl Handler for Application {
4550
req.extensions().get::<SocketAddr>().unwrap()
4651
);
4752

48-
// Create an Hyper Response and send it back to the middlewares chain
53+
// Create a Hyper Response and send it back to the middlewares chain
4954
Ok(Response::builder().body(Body::from("¡Hola!")).unwrap())
5055
}
5156
}
5257

5358
struct FirstMiddleware {}
5459

5560
impl BeforeMiddleware for FirstMiddleware {
56-
fn before(&self, req: &mut Request) -> Result<()> {
61+
fn before(&self, req: &mut Request) -> Result {
5762
println!("First Middleware called!");
5863

5964
// Access the Hyper incoming Request
60-
println!("URI Path: {}", req.uri().path());
65+
println!("First - URI Path: {}", req.uri().path());
6166

6267
Ok(())
6368
}
6469

65-
fn catch(&self, _: &mut Request, err: Error) -> Result<()> {
70+
fn catch(&self, _: &mut Request, err: Error) -> Result {
6671
Err(err)
6772
}
6873
}
@@ -91,7 +96,7 @@ impl AfterMiddleware for SecondMiddleware {
9196
}
9297
}
9398

94-
#[tokio::main(flavor = "multi_thread", worker_threads = 32)]
99+
#[tokio::main(flavor = "multi_thread")]
95100
async fn main() -> Result {
96101
// 0. Define some app options (example only)
97102
let opts = Config {
@@ -130,8 +135,7 @@ cargo run --example server
130135

131136
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in current work by you, as defined in the Apache-2.0 license, shall be dual licensed as described below, without any additional terms or conditions.
132137

133-
Feel free to send some [Pull request](https://github.com/static-web-server/hyper-middleware/pulls) or [issue](https://github.com/static-web-server/hyper-middleware/issues).
134-
138+
Feel free to send some [Pull request](https://github.com/static-web-server/hyper-middleware/pulls) or file an [issue](https://github.com/static-web-server/hyper-middleware/issues).
135139

136140
## License
137141

examples/server.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct Application {
2222
impl Handler for Application {
2323
fn handle(&self, req: &mut Request) -> Result<Response> {
2424
// Access the Hyper incoming Request
25-
println!("URI Path: {}", req.uri().path());
25+
println!("Handler - URI Path: {}", req.uri().path());
2626

2727
// Access the custom app options
2828
println!("Config Root: {}", self.opts.root.display());
@@ -33,24 +33,24 @@ impl Handler for Application {
3333
req.extensions().get::<SocketAddr>().unwrap()
3434
);
3535

36-
// Create an Hyper Response and send it back to the middlewares chain
36+
// Create a Hyper Response and send it back to the middlewares chain
3737
Ok(Response::builder().body(Body::from("¡Hola!")).unwrap())
3838
}
3939
}
4040

4141
struct FirstMiddleware {}
4242

4343
impl BeforeMiddleware for FirstMiddleware {
44-
fn before(&self, req: &mut Request) -> Result<()> {
44+
fn before(&self, req: &mut Request) -> Result {
4545
println!("First Middleware called!");
4646

4747
// Access the Hyper incoming Request
48-
println!("URI Path: {}", req.uri().path());
48+
println!("First - URI Path: {}", req.uri().path());
4949

5050
Ok(())
5151
}
5252

53-
fn catch(&self, _: &mut Request, err: Error) -> Result<()> {
53+
fn catch(&self, _: &mut Request, err: Error) -> Result {
5454
Err(err)
5555
}
5656
}
@@ -79,7 +79,7 @@ impl AfterMiddleware for SecondMiddleware {
7979
}
8080
}
8181

82-
#[tokio::main(flavor = "multi_thread", worker_threads = 32)]
82+
#[tokio::main(flavor = "multi_thread")]
8383
async fn main() -> Result {
8484
// 0. Define some app options (example only)
8585
let opts = Config {

0 commit comments

Comments
 (0)