aboutsummaryrefslogtreecommitdiffstats
path: root/src/custom_filters.rs
diff options
context:
space:
mode:
authorYigit Sever2021-04-13 04:05:44 +0300
committerYigit Sever2021-04-13 04:05:49 +0300
commitb06cbd69fc2a7544f6f62c20cbdfb30bda194101 (patch)
treee639c13328c3c0083f3f343fb5633290ec2bf29c /src/custom_filters.rs
parent42cad1e409727ae8e1fd9f9d1c0b520e9c0565f8 (diff)
downloadgradecoin-b06cbd69fc2a7544f6f62c20cbdfb30bda194101.tar.gz
gradecoin-b06cbd69fc2a7544f6f62c20cbdfb30bda194101.tar.bz2
gradecoin-b06cbd69fc2a7544f6f62c20cbdfb30bda194101.zip
Housekeeping
Moved tests out of routes.rs into their own file Learned how to use lib.rs, now we have cargo doc support as well
Diffstat (limited to 'src/custom_filters.rs')
-rw-r--r--src/custom_filters.rs18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/custom_filters.rs b/src/custom_filters.rs
index f93f572..dfdae04 100644
--- a/src/custom_filters.rs
+++ b/src/custom_filters.rs
@@ -1,30 +1,38 @@
1use gradecoin::schema::{AuthRequest, Block, Db, Transaction}; 1/// Functions that extracts Structs to be used in warp routines
2use crate::schema::{AuthRequest, Block, Db, Transaction};
2use std::convert::Infallible; 3use std::convert::Infallible;
3use warp::{Filter, Rejection}; 4use warp::{Filter, Rejection};
4 5
5// Database context for routes 6/// Wraps the database to be used in warp routes
6pub fn with_db(db: Db) -> impl Filter<Extract = (Db,), Error = Infallible> + Clone { 7pub fn with_db(db: Db) -> impl Filter<Extract = (Db,), Error = Infallible> + Clone {
7 warp::any().map(move || db.clone()) 8 warp::any().map(move || db.clone())
8} 9}
9 10
10// Accept only json encoded User body and reject big payloads 11/// Extracts an `AuthRequest` JSON body from the request
12/// Accepts only JSON encoded `AuthRequest` body and rejects big payloads
13///
11// TODO: find a good limit for this, (=e2482057; 8 char String + rsa pem) <11-04-21, yigit> // 14// TODO: find a good limit for this, (=e2482057; 8 char String + rsa pem) <11-04-21, yigit> //
12pub fn auth_request_json_body() -> impl Filter<Extract = (AuthRequest,), Error = Rejection> + Clone 15pub fn auth_request_json_body() -> impl Filter<Extract = (AuthRequest,), Error = Rejection> + Clone
13{ 16{
14 warp::body::content_length_limit(1024 * 32).and(warp::body::json()) 17 warp::body::content_length_limit(1024 * 32).and(warp::body::json())
15} 18}
16 19
17// Accept only json encoded Transaction body and reject big payloads 20/// Extracts an `Transaction` JSON body from the request
21/// Accepts only JSON encoded `Transaction` body and rejects big payloads
18// TODO: find a good limit for this <11-04-21, yigit> // 22// TODO: find a good limit for this <11-04-21, yigit> //
19pub fn transaction_json_body() -> impl Filter<Extract = (Transaction,), Error = Rejection> + Clone { 23pub fn transaction_json_body() -> impl Filter<Extract = (Transaction,), Error = Rejection> + Clone {
20 warp::body::content_length_limit(1024 * 32).and(warp::body::json()) 24 warp::body::content_length_limit(1024 * 32).and(warp::body::json())
21} 25}
22 26
27/// Extracts the value of the `Authorization` header field, hopefully a valid JWT
28/// Used in Authorization for `Block` and `Transaction` proposals
29/// Rejects the request if the Authorization header does not exist
23pub fn auth_header() -> impl Filter<Extract = (String,), Error = Rejection> + Clone { 30pub fn auth_header() -> impl Filter<Extract = (String,), Error = Rejection> + Clone {
24 warp::header::header::<String>("Authorization") 31 warp::header::header::<String>("Authorization")
25} 32}
26 33
27// Accept only json encoded Block body and reject big payloads 34/// Extracts an `Block` JSON body from the request
35/// Accepts only JSON encoded `Block` body and rejects big payloads
28// TODO: find a good limit for this <11-04-21, yigit> // 36// TODO: find a good limit for this <11-04-21, yigit> //
29pub fn block_json_body() -> impl Filter<Extract = (Block,), Error = Rejection> + Clone { 37pub fn block_json_body() -> impl Filter<Extract = (Block,), Error = Rejection> + Clone {
30 warp::body::content_length_limit(1024 * 32).and(warp::body::json()) 38 warp::body::content_length_limit(1024 * 32).and(warp::body::json())