From b06cbd69fc2a7544f6f62c20cbdfb30bda194101 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Tue, 13 Apr 2021 04:05:44 +0300 Subject: 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 --- src/custom_filters.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/custom_filters.rs') 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 @@ -use gradecoin::schema::{AuthRequest, Block, Db, Transaction}; +/// Functions that extracts Structs to be used in warp routines +use crate::schema::{AuthRequest, Block, Db, Transaction}; use std::convert::Infallible; use warp::{Filter, Rejection}; -// Database context for routes +/// Wraps the database to be used in warp routes pub fn with_db(db: Db) -> impl Filter + Clone { warp::any().map(move || db.clone()) } -// Accept only json encoded User body and reject big payloads +/// Extracts an `AuthRequest` JSON body from the request +/// Accepts only JSON encoded `AuthRequest` body and rejects 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 + Clone { warp::body::content_length_limit(1024 * 32).and(warp::body::json()) } -// Accept only json encoded Transaction body and reject big payloads +/// Extracts an `Transaction` JSON body from the request +/// Accepts only JSON encoded `Transaction` body and rejects big payloads // TODO: find a good limit for this <11-04-21, yigit> // pub fn transaction_json_body() -> impl Filter + Clone { warp::body::content_length_limit(1024 * 32).and(warp::body::json()) } +/// Extracts the value of the `Authorization` header field, hopefully a valid JWT +/// Used in Authorization for `Block` and `Transaction` proposals +/// Rejects the request if the Authorization header does not exist pub fn auth_header() -> impl Filter + Clone { warp::header::header::("Authorization") } -// Accept only json encoded Block body and reject big payloads +/// Extracts an `Block` JSON body from the request +/// Accepts only JSON encoded `Block` body and rejects big payloads // TODO: find a good limit for this <11-04-21, yigit> // pub fn block_json_body() -> impl Filter + Clone { warp::body::content_length_limit(1024 * 32).and(warp::body::json()) -- cgit v1.2.3-70-g09d2