aboutsummaryrefslogtreecommitdiffstats
path: root/src/custom_filters.rs
blob: f93f57285fb5f52b223cb347f1f80bb374ad2377 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use gradecoin::schema::{AuthRequest, Block, Db, Transaction};
use std::convert::Infallible;
use warp::{Filter, Rejection};

// Database context for routes
pub fn with_db(db: Db) -> impl Filter<Extract = (Db,), Error = Infallible> + Clone {
    warp::any().map(move || db.clone())
}

// Accept only json encoded User body and reject big payloads
// TODO: find a good limit for this, (=e2482057; 8 char String + rsa pem) <11-04-21, yigit> //
pub fn auth_request_json_body() -> impl Filter<Extract = (AuthRequest,), Error = Rejection> + Clone
{
    warp::body::content_length_limit(1024 * 32).and(warp::body::json())
}

// Accept only json encoded Transaction body and reject big payloads
// TODO: find a good limit for this <11-04-21, yigit> //
pub fn transaction_json_body() -> impl Filter<Extract = (Transaction,), Error = Rejection> + Clone {
    warp::body::content_length_limit(1024 * 32).and(warp::body::json())
}

pub fn auth_header() -> impl Filter<Extract = (String,), Error = Rejection> + Clone {
    warp::header::header::<String>("Authorization")
}

// Accept only json encoded Block body and reject big payloads
// TODO: find a good limit for this <11-04-21, yigit> //
pub fn block_json_body() -> impl Filter<Extract = (Block,), Error = Rejection> + Clone {
    warp::body::content_length_limit(1024 * 32).and(warp::body::json())
}