Change content length limits of http routes
This commit is contained in:
parent
d67ea597e3
commit
69b18cc659
5 changed files with 60 additions and 39 deletions
|
@ -1,6 +1,8 @@
|
|||
use warp::http;
|
||||
use warp::Filter;
|
||||
|
||||
const MAX: u64 = 1024 * 1024 * 1024 * 4; // 4 GiB
|
||||
|
||||
pub fn config() -> impl Filter<Extract = impl warp::Reply, Error = warp::Rejection> + Clone {
|
||||
// Set base path
|
||||
let base = warp::path("import").and(warp::path::end());
|
||||
|
@ -9,7 +11,7 @@ pub fn config() -> impl Filter<Extract = impl warp::Reply, Error = warp::Rejecti
|
|||
// Set post method
|
||||
let post = base
|
||||
.and(warp::post())
|
||||
.and(warp::body::content_length_limit(1024 * 1024 * 1024)) // 1GiB
|
||||
.and(warp::body::content_length_limit(MAX))
|
||||
.and_then(handler);
|
||||
// Specify route
|
||||
opts.or(post)
|
||||
|
|
|
@ -11,8 +11,10 @@ use surrealdb::Session;
|
|||
use warp::path;
|
||||
use warp::Filter;
|
||||
|
||||
const MAX: u64 = 1024 * 16; // 16 KiB
|
||||
|
||||
#[derive(Default, Deserialize, Debug, Clone)]
|
||||
pub struct Query {
|
||||
struct Query {
|
||||
pub limit: Option<String>,
|
||||
pub start: Option<String>,
|
||||
}
|
||||
|
@ -30,24 +32,30 @@ pub fn config() -> impl Filter<Extract = impl warp::Reply, Error = warp::Rejecti
|
|||
// Routes for a table
|
||||
// ------------------------------
|
||||
|
||||
// All methods
|
||||
let base = warp::any();
|
||||
// Get session config
|
||||
let base = base.and(conf::build());
|
||||
// Get content type header
|
||||
let base = base.and(warp::header::<String>(http::header::CONTENT_TYPE.as_str()));
|
||||
// Set base path for all
|
||||
let base = base.and(path!("key" / String).and(warp::path::end()));
|
||||
// Set select method
|
||||
let select = base.and(warp::get()).and(warp::query()).and_then(select_all);
|
||||
let select = warp::any()
|
||||
.and(warp::get())
|
||||
.and(conf::build())
|
||||
.and(warp::header::<String>(http::header::CONTENT_TYPE.as_str()))
|
||||
.and(path!("key" / String).and(warp::path::end()))
|
||||
.and(warp::query())
|
||||
.and_then(select_all);
|
||||
// Set create method
|
||||
let create = base
|
||||
let create = warp::any()
|
||||
.and(warp::post())
|
||||
.and(warp::body::content_length_limit(1024 * 1024)) // 1MiB
|
||||
.and(conf::build())
|
||||
.and(warp::header::<String>(http::header::CONTENT_TYPE.as_str()))
|
||||
.and(path!("key" / String).and(warp::path::end()))
|
||||
.and(warp::body::content_length_limit(MAX))
|
||||
.and(warp::body::bytes())
|
||||
.and_then(create_all);
|
||||
// Set delete method
|
||||
let delete = base.and(warp::delete()).and_then(delete_all);
|
||||
let delete = warp::any()
|
||||
.and(warp::delete())
|
||||
.and(conf::build())
|
||||
.and(warp::header::<String>(http::header::CONTENT_TYPE.as_str()))
|
||||
.and(path!("key" / String).and(warp::path::end()))
|
||||
.and_then(delete_all);
|
||||
// Specify route
|
||||
let all = select.or(create).or(delete);
|
||||
|
||||
|
@ -55,36 +63,47 @@ pub fn config() -> impl Filter<Extract = impl warp::Reply, Error = warp::Rejecti
|
|||
// Routes for a thing
|
||||
// ------------------------------
|
||||
|
||||
// All methods
|
||||
let base = warp::any();
|
||||
// Get session config
|
||||
let base = base.and(conf::build());
|
||||
// Get content type header
|
||||
let base = base.and(warp::header::<String>(http::header::CONTENT_TYPE.as_str()));
|
||||
// Set base path for one
|
||||
let base = base.and(path!("key" / String / String).and(warp::path::end()));
|
||||
// Set select method
|
||||
let select = base.and(warp::get()).and_then(select_one);
|
||||
let select = warp::any()
|
||||
.and(warp::get())
|
||||
.and(conf::build())
|
||||
.and(warp::header::<String>(http::header::CONTENT_TYPE.as_str()))
|
||||
.and(path!("key" / String / String).and(warp::path::end()))
|
||||
.and_then(select_one);
|
||||
// Set create method
|
||||
let create = base
|
||||
let create = warp::any()
|
||||
.and(warp::post())
|
||||
.and(warp::body::content_length_limit(1024 * 1024)) // 1MiB
|
||||
.and(conf::build())
|
||||
.and(warp::header::<String>(http::header::CONTENT_TYPE.as_str()))
|
||||
.and(path!("key" / String / String).and(warp::path::end()))
|
||||
.and(warp::body::content_length_limit(MAX))
|
||||
.and(warp::body::bytes())
|
||||
.and_then(create_one);
|
||||
// Set update method
|
||||
let update = base
|
||||
let update = warp::any()
|
||||
.and(warp::put())
|
||||
.and(warp::body::content_length_limit(1024 * 1024)) // 1MiB
|
||||
.and(conf::build())
|
||||
.and(warp::header::<String>(http::header::CONTENT_TYPE.as_str()))
|
||||
.and(path!("key" / String / String).and(warp::path::end()))
|
||||
.and(warp::body::content_length_limit(MAX))
|
||||
.and(warp::body::bytes())
|
||||
.and_then(update_one);
|
||||
// Set modify method
|
||||
let modify = base
|
||||
let modify = warp::any()
|
||||
.and(warp::patch())
|
||||
.and(warp::body::content_length_limit(1024 * 1024)) // 1MiB
|
||||
.and(conf::build())
|
||||
.and(warp::header::<String>(http::header::CONTENT_TYPE.as_str()))
|
||||
.and(path!("key" / String / String).and(warp::path::end()))
|
||||
.and(warp::body::content_length_limit(MAX))
|
||||
.and(warp::body::bytes())
|
||||
.and_then(modify_one);
|
||||
// Set delete method
|
||||
let delete = base.and(warp::delete()).and_then(delete_one);
|
||||
let delete = warp::any()
|
||||
.and(warp::delete())
|
||||
.and(conf::build())
|
||||
.and(warp::header::<String>(http::header::CONTENT_TYPE.as_str()))
|
||||
.and(path!("key" / String / String).and(warp::path::end()))
|
||||
.and_then(delete_one);
|
||||
// Specify route
|
||||
let one = select.or(create).or(update).or(modify).or(delete);
|
||||
|
||||
|
|
|
@ -2,16 +2,15 @@ use crate::net::head;
|
|||
use warp::http;
|
||||
use warp::Filter;
|
||||
|
||||
const MAX: u64 = 1024; // 1 KiB
|
||||
|
||||
pub fn config() -> impl Filter<Extract = impl warp::Reply, Error = warp::Rejection> + Clone {
|
||||
// Set base path
|
||||
let base = warp::path("signin").and(warp::path::end());
|
||||
// Set opts method
|
||||
let opts = base.and(warp::options()).map(warp::reply);
|
||||
// Set post method
|
||||
let post = base
|
||||
.and(warp::post())
|
||||
.and(warp::body::content_length_limit(1024 * 1024)) // 1MiB
|
||||
.and_then(handler);
|
||||
let post = base.and(warp::post()).and(warp::body::content_length_limit(MAX)).and_then(handler);
|
||||
// Specify route
|
||||
opts.or(post).with(head::cors())
|
||||
}
|
||||
|
|
|
@ -2,16 +2,15 @@ use crate::net::head;
|
|||
use warp::http;
|
||||
use warp::Filter;
|
||||
|
||||
const MAX: u64 = 1024; // 1 KiB
|
||||
|
||||
pub fn config() -> impl Filter<Extract = impl warp::Reply, Error = warp::Rejection> + Clone {
|
||||
// Set base path
|
||||
let base = warp::path("signup").and(warp::path::end());
|
||||
// Set opts method
|
||||
let opts = base.and(warp::options()).map(warp::reply);
|
||||
// Set post method
|
||||
let post = base
|
||||
.and(warp::post())
|
||||
.and(warp::body::content_length_limit(1024 * 1024)) // 1MiB
|
||||
.and_then(handler);
|
||||
let post = base.and(warp::post()).and(warp::body::content_length_limit(MAX)).and_then(handler);
|
||||
// Specify route
|
||||
opts.or(post).with(head::cors())
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@ use futures::{FutureExt, StreamExt};
|
|||
use surrealdb::Session;
|
||||
use warp::Filter;
|
||||
|
||||
const MAX: u64 = 1024 * 1024; // 1 MiB
|
||||
|
||||
pub fn config() -> impl Filter<Extract = impl warp::Reply, Error = warp::Rejection> + Clone {
|
||||
// Set base path
|
||||
let base = warp::path("sql").and(warp::path::end());
|
||||
|
@ -18,7 +20,7 @@ pub fn config() -> impl Filter<Extract = impl warp::Reply, Error = warp::Rejecti
|
|||
.and(warp::post())
|
||||
.and(conf::build())
|
||||
.and(warp::header::<String>(http::header::CONTENT_TYPE.as_str()))
|
||||
.and(warp::body::content_length_limit(1024 * 1024)) // 1MiB
|
||||
.and(warp::body::content_length_limit(MAX))
|
||||
.and(warp::body::bytes())
|
||||
.and_then(handler);
|
||||
// Set sock method
|
||||
|
|
Loading…
Reference in a new issue