From eae0480fe06f610e73fa79e157ebe3b1777bf6e6 Mon Sep 17 00:00:00 2001 From: Sanskar Jethi Date: Sun, 6 Nov 2022 09:21:00 +0000 Subject: [PATCH 1/3] fix: log level not working (#303) * fix: remove extra log level config * style: reformat integration_tests/conftest.py --- integration_tests/conftest.py | 20 +++++++++----------- robyn/env_populator.py | 6 +----- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/integration_tests/conftest.py b/integration_tests/conftest.py index 2ef0de2b4..220305f0f 100644 --- a/integration_tests/conftest.py +++ b/integration_tests/conftest.py @@ -7,26 +7,26 @@ import os import time + def spawn_process(command: List[str]) -> subprocess.Popen: if sys.platform.startswith("win32"): command[0] = "python" - process = subprocess.Popen(command, shell=True, creationflags=subprocess.CREATE_NEW_PROCESS_GROUP) + process = subprocess.Popen( + command, shell=True, creationflags=subprocess.CREATE_NEW_PROCESS_GROUP + ) return process process = subprocess.Popen(command, preexec_fn=os.setsid) - return process - + return process def kill_process(process: subprocess.Popen) -> None: if sys.platform.startswith("win32"): process.send_signal(signal.CTRL_BREAK_EVENT) process.kill() - return + return os.killpg(os.getpgid(process.pid), signal.SIGKILL) - - - - + + @pytest.fixture(scope="session") def session(): os.environ["ROBYN_URL"] = "127.0.0.1" @@ -37,8 +37,6 @@ def session(): time.sleep(5) yield kill_process(process) - - @pytest.fixture(scope="session") @@ -76,6 +74,7 @@ def dev_session(): yield kill_process(process) + @pytest.fixture(scope="session") def test_session(): os.environ["ROBYN_URL"] = "127.0.0.1" @@ -87,4 +86,3 @@ def test_session(): time.sleep(5) yield kill_process(process) - diff --git a/robyn/env_populator.py b/robyn/env_populator.py index aae9af37d..0dca052b3 100644 --- a/robyn/env_populator.py +++ b/robyn/env_populator.py @@ -1,12 +1,8 @@ -from distutils.command.config import config -import os import logging +import os from pathlib import Path - -# set the logger that will log the environment variables imported from robyn.env and the ones already set logger = logging.getLogger(__name__) -logging.basicConfig(level=logging.INFO) # parse the configuration file returning a list of tuples (key, value) containing the environment variables From 04a53fc3cc441cf59080507be84a3d3da9f829ff Mon Sep 17 00:00:00 2001 From: Suhail Malik Date: Mon, 7 Nov 2022 19:54:40 +0530 Subject: [PATCH 2/3] add route type enum (#299) * add route type enum * update enum name and location * update code with renaming some types * cargo fmt --- src/routers/middleware_router.rs | 16 +++++++----- src/routers/mod.rs | 1 + src/routers/types.rs | 15 ++++++++++++ src/server.rs | 42 ++++++++++++++++++-------------- 4 files changed, 50 insertions(+), 24 deletions(-) create mode 100644 src/routers/types.rs diff --git a/src/routers/middleware_router.rs b/src/routers/middleware_router.rs index 9ed26c708..4064baef1 100644 --- a/src/routers/middleware_router.rs +++ b/src/routers/middleware_router.rs @@ -9,6 +9,8 @@ use matchit::Router; use anyhow::{bail, Error, Result}; +use crate::routers::types::MiddlewareRoute; + /// Contains the thread safe hashmaps of different routes pub struct MiddlewareRouter { @@ -25,11 +27,13 @@ impl MiddlewareRouter { } #[inline] - fn get_relevant_map(&self, route: &str) -> Option<&RwLock>> { + fn get_relevant_map( + &self, + route: MiddlewareRoute, + ) -> Option<&RwLock>> { match route { - "BEFORE_REQUEST" => Some(&self.before_request), - "AFTER_REQUEST" => Some(&self.after_request), - _ => None, + MiddlewareRoute::BeforeRequest => Some(&self.before_request), + MiddlewareRoute::AfterRequest => Some(&self.after_request), } } @@ -37,7 +41,7 @@ impl MiddlewareRouter { // Inserts them in the router according to their nature(CoRoutine/SyncFunction) pub fn add_route( &self, - route_type: &str, // we can just have route type as WS + route_type: MiddlewareRoute, route: &str, handler: Py, is_async: bool, @@ -64,7 +68,7 @@ impl MiddlewareRouter { pub fn get_route( &self, - route_method: &str, + route_method: MiddlewareRoute, route: &str, // check for the route method here ) -> Option<((PyFunction, u8), HashMap)> { // need to split this function in multiple smaller functions diff --git a/src/routers/mod.rs b/src/routers/mod.rs index 8dff051de..77dd7c416 100644 --- a/src/routers/mod.rs +++ b/src/routers/mod.rs @@ -1,4 +1,5 @@ pub mod const_router; pub mod middleware_router; pub mod router; +pub mod types; pub mod web_socket_router; diff --git a/src/routers/types.rs b/src/routers/types.rs new file mode 100644 index 000000000..6d1da332e --- /dev/null +++ b/src/routers/types.rs @@ -0,0 +1,15 @@ +#[derive(Debug)] +pub enum MiddlewareRoute { + BeforeRequest, + AfterRequest, +} + +impl MiddlewareRoute { + pub fn from_str(input: &str) -> MiddlewareRoute { + match input { + "BEFORE_REQUEST" => MiddlewareRoute::BeforeRequest, + "AFTER_REQUEST" => MiddlewareRoute::AfterRequest, + _ => panic!("Invalid route type enum."), + } + } +} diff --git a/src/server.rs b/src/server.rs index 7c076082d..f924b79ed 100644 --- a/src/server.rs +++ b/src/server.rs @@ -3,7 +3,9 @@ use crate::io_helpers::apply_headers; use crate::request_handler::{handle_http_middleware_request, handle_http_request}; use crate::routers::const_router::ConstRouter; + use crate::routers::router::Router; +use crate::routers::types::MiddlewareRoute; use crate::routers::{middleware_router::MiddlewareRouter, web_socket_router::WebSocketRouter}; use crate::shared_socket::SocketHeld; use crate::types::{Headers, PyFunction}; @@ -296,6 +298,9 @@ impl Server { number_of_params: u8, ) { debug!("MiddleWare Route added for {} {} ", route_type, route); + + let route_type = MiddlewareRoute::from_str(route_type); + self.middleware_router .add_route(route_type, route, handler, is_async, number_of_params) .unwrap(); @@ -389,23 +394,24 @@ async fn index( let headers = merge_headers(&global_headers, req.headers()).await; // need a better name for this - let tuple_params = match middleware_router.get_route("BEFORE_REQUEST", req.uri().path()) { - Some(((handler_function, number_of_params), route_params)) => { - let x = handle_http_middleware_request( - handler_function, - number_of_params, - &headers, - &mut payload, - &req, - route_params, - queries.clone(), - ) - .await; - debug!("Middleware contents {:?}", x); - x - } - None => HashMap::new(), - }; + let tuple_params = + match middleware_router.get_route(MiddlewareRoute::BeforeRequest, req.uri().path()) { + Some(((handler_function, number_of_params), route_params)) => { + let x = handle_http_middleware_request( + handler_function, + number_of_params, + &headers, + &mut payload, + &req, + route_params, + queries.clone(), + ) + .await; + debug!("Middleware contents {:?}", x); + x + } + None => HashMap::new(), + }; debug!("These are the tuple params {:?}", tuple_params); @@ -451,7 +457,7 @@ async fn index( }; if let Some(((handler_function, number_of_params), route_params)) = - middleware_router.get_route("AFTER_REQUEST", req.uri().path()) + middleware_router.get_route(MiddlewareRoute::AfterRequest, req.uri().path()) { let x = handle_http_middleware_request( handler_function, From 8edd82bebdbaffb1523a74ac912be2ff4c333920 Mon Sep 17 00:00:00 2001 From: Sanskar Jethi Date: Thu, 10 Nov 2022 05:30:00 +0000 Subject: [PATCH 3/3] Release v0.18.3 --- Cargo.lock | 2 +- Cargo.toml | 2 +- pyproject.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5f9faa94d..99e37ac4a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1164,7 +1164,7 @@ checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" [[package]] name = "robyn" -version = "0.18.2" +version = "0.18.3" dependencies = [ "actix", "actix-files", diff --git a/Cargo.toml b/Cargo.toml index 9c6cbeab4..fa6a6c190 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "robyn" -version = "0.18.2" +version = "0.18.3" authors = ["Sanskar Jethi "] edition = "2018" description = "A web server that is fast!" diff --git a/pyproject.toml b/pyproject.toml index 43b08341c..633d77b2f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ name = "robyn" -version = "0.18.2" +version = "0.18.3" description = "A web server that is fast!" authors = ["Sanskar Jethi "]