Skip to content

Commit

Permalink
Fill in body section.
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeMathWalker committed Dec 31, 2023
1 parent 0e1b207 commit d7711c4
Show file tree
Hide file tree
Showing 28 changed files with 1,551 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
```rust title="src/custom_limit/blueprint.rs"
use pavex::blueprint::{constructor::Lifecycle, Blueprint};
use pavex::f;
use pavex::request::body::BodySizeLimit;
pub fn body_size_limit() -> BodySizeLimit {
BodySizeLimit::Enabled {
max_n_bytes: 10_485_760, // 10 MBs
}
}
pub fn blueprint() -> Blueprint {
let mut bp = Blueprint::new();
bp.constructor(f!(crate::body_size_limit), Lifecycle::Singleton);
// [...]
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
```rust title="src/buffered_body/routes.rs" hl_lines="4"
use pavex::http::StatusCode;
use pavex::request::body::BufferedBody;
pub fn handler(body: &BufferedBody) -> StatusCode {
format!("The incoming request contains {} bytes", body.bytes.len());
// [...]
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
```rust title="src/granular_limits/blueprint.rs"
use pavex::blueprint::{constructor::Lifecycle, router::POST, Blueprint};
use pavex::f;
use pavex::request::body::BodySizeLimit;
pub fn blueprint() -> Blueprint {
let mut bp = Blueprint::new();
bp.nest(upload_bp());
// Other routes...
bp
}
fn upload_bp() -> Blueprint {
let mut bp = Blueprint::new();
// This limit will only apply to the routes registered
// in this nested blueprint.
bp.constructor(f!(crate::upload_size_limit), Lifecycle::Singleton);
bp.route(POST, "/upload", f!(crate::upload));
bp
}
pub fn upload_size_limit() -> BodySizeLimit {
BodySizeLimit::Enabled {
max_n_bytes: 1_073_741_824, // 1GB
}
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```rust title="src/no_limit/blueprint.rs"
use pavex::blueprint::{constructor::Lifecycle, Blueprint};
use pavex::f;
use pavex::request::body::BodySizeLimit;
pub fn body_size_limit() -> BodySizeLimit {
BodySizeLimit::Disabled
}
pub fn blueprint() -> Blueprint {
let mut bp = Blueprint::new();
bp.constructor(f!(crate::body_size_limit), Lifecycle::Singleton);
// [...]
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
Loading

0 comments on commit d7711c4

Please sign in to comment.