-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: limits should be sorted * fix: fmt * fix: fmt * fix: cargo path * fix: doc ci
- Loading branch information
Showing
11 changed files
with
80 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "limits" | ||
version = "0.1.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
[dependencies] | ||
viz = { path = "../../viz", features = ["limits", "json"] } | ||
|
||
serde = {version = "1.0", features = ["derive"] } | ||
tokio = { version = "1.0", features = [ | ||
"rt-multi-thread", | ||
"macros", | ||
] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#![deny(warnings)] | ||
|
||
use std::net::SocketAddr; | ||
use viz::{middleware::limits, Request, RequestExt, Result, Router, Server, ServiceMaker}; | ||
|
||
async fn echo(mut req: Request) -> Result<String> { | ||
Ok(format!("len: {}", req.text().await?.len())) | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
let addr = SocketAddr::from(([127, 0, 0, 1], 3000)); | ||
println!("listening on {addr}"); | ||
|
||
let limits = viz::types::Limits::new() | ||
.insert("payload", 1000 * 1024 * 1024) | ||
.insert("text", 1000 * 1024 * 1024) | ||
.insert("bytes", 1000 * 1024 * 1024) | ||
.insert("json", 1000 * 1024 * 1024); | ||
|
||
let app = Router::new() | ||
.post("/", echo) | ||
// limit body size | ||
.with(limits::Config::default().limits(limits)); | ||
|
||
if let Err(err) = Server::bind(&addr).serve(ServiceMaker::from(app)).await { | ||
println!("{err}"); | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters