Skip to content

Commit

Permalink
chore: fix pyproject and poetry run test_server command (#746)
Browse files Browse the repository at this point in the history
* chore: fix pyproject and poetry run test_server command

* fix: fix set_token method and some typing issues

* fix: improve Headers class by adding __getitem__

* fix: tests for macos

* docs: improve docs
  • Loading branch information
AntoineRR authored Feb 5, 2024
1 parent a097fc7 commit 13e9f13
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ Either, by using the `headers` field in the `Request` object:
print("These are the request headers: ", headers)

headers.set("modified", "modified_value")
headers["new_header"] = "new_value" # This syntax is also valid

print("These are the modified request headers: ", headers)

Expand Down
3 changes: 3 additions & 0 deletions integration_tests/base_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,9 @@ def main():
class BasicAuthHandler(AuthenticationHandler):
def authenticate(self, request: Request) -> Optional[Identity]:
token = self.token_getter.get_token(request)
if token is not None:
# Useless but we call the set_token method for testing purposes
self.token_getter.set_token(request, token)
if token == "valid":
return Identity(claims={"key": "value"})
return None
Expand Down
5 changes: 2 additions & 3 deletions integration_tests/helpers/network_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@


def get_network_host():
hostname = socket.gethostname()
ip_address = socket.gethostbyname(hostname)

# windows doesn't support 0.0.0.0
if platform.system() == "Windows":
hostname = socket.gethostname()
ip_address = socket.gethostbyname(hostname)
return ip_address
else:
return "0.0.0.0"
2 changes: 1 addition & 1 deletion integration_tests/subroutes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from robyn import SubRouter, jsonify, WebSocket

from subroutes.di_subrouter import di_subrouter
from .di_subrouter import di_subrouter

sub_router = SubRouter(__name__, prefix="/sub_router")

Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ name = "robyn"
version = "0.51.1"
description = "A High-Performance, Community-Driven, and Innovator Friendly Web Framework with a Rust runtime."
authors = [{ name = "Sanskar Jethi", email = "[email protected]" }]
repository = "https://github.com/sparckles/robyn"
documentation = "https://robyn.tech/"
classifiers = [
"Development Status :: 3 - Alpha",
"Environment :: Web Environment",
Expand Down Expand Up @@ -40,13 +38,15 @@ robyn = "robyn.cli:run"
"templating" = ["jinja2 == 3.0.1"]

[project.urls]
Documentation = "https://robyn.tech/"
Repository = "https://github.com/sparckles/robyn"
Issues = "https://github.com/sparckles/robyn/issues"
Changelog = "https://github.com/sparckles/robyn/blob/main/CHANGELOG.md"


[tool.poetry]
name = "robyn"
version = "0.51.0"
version = "0.51.1"
description = "A High-Performance, Community-Driven, and Innovator Friendly Web Framework with a Rust runtime."
authors = ["Sanskar Jethi <[email protected]>"]

Expand Down
8 changes: 5 additions & 3 deletions robyn/authentication.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from abc import ABC, abstractclassmethod, abstractmethod
from abc import ABC, abstractmethod
from typing import Optional

from robyn.robyn import Headers, Identity, Request, Response
Expand All @@ -23,7 +23,8 @@ def scheme(self) -> str:
"""
return self.__class__.__name__

@abstractclassmethod
@classmethod
@abstractmethod
def get_token(cls, request: Request) -> Optional[str]:
"""
Gets the token from the request.
Expand All @@ -33,7 +34,8 @@ def get_token(cls, request: Request) -> Optional[str]:
"""
raise NotImplementedError()

@abstractclassmethod
@classmethod
@abstractmethod
def set_token(cls, request: Request, token: str):
"""
Sets the token in the request.
Expand Down
6 changes: 3 additions & 3 deletions robyn/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sys
from typing import Optional
import webbrowser
from InquirerPy import prompt
from InquirerPy.resolver import prompt
from InquirerPy.base.control import Choice
from .argument_parser import Config
from .reloader import create_rust_file, setup_reloader
Expand Down Expand Up @@ -49,9 +49,9 @@ def create_robyn_app():
},
]
result = prompt(questions=questions)
project_dir_path = Path(result["directory"]).resolve()
project_dir_path = Path(str(result["directory"])).resolve()
docker = result["docker"]
project_type = result["project_type"]
project_type = str(result["project_type"])

final_project_dir_path = (CURRENT_WORKING_DIR / project_dir_path).resolve()

Expand Down
20 changes: 18 additions & 2 deletions robyn/robyn.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ class Headers:
def __init__(self, default_headers: Optional[dict]) -> None:
pass

def __getitem__(self, key: str) -> Optional[str]:
pass

def __setitem__(self, key: str, value: str) -> None:
pass

def set(self, key: str, value: str) -> None:
"""
Sets the value of the header with the given key.
Expand Down Expand Up @@ -227,6 +233,16 @@ class Headers:
"""
pass

def append(self, key: str, value: str) -> None:
"""
Appends the value to the header with the given key.
Args:
key (str): The key of the header
value (str): The value of the header
"""
pass

def is_empty(self) -> bool:
pass

Expand Down Expand Up @@ -290,9 +306,9 @@ class Server:
index_file: Optional[str],
) -> None:
pass
def apply_request_header(self, key: str, value: str) -> None:
def apply_request_headers(self, headers: Headers) -> None:
pass
def apply_response_header(self, key: str, value: str) -> None:
def apply_response_headers(self, headers: Headers) -> None:
pass

def add_route(
Expand Down
8 changes: 8 additions & 0 deletions src/types/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ impl Headers {
pub fn __repr__(&self) -> String {
format!("{:?}", self.headers)
}

pub fn __setitem__(&mut self, key: String, value: String) {
self.set(key, value);
}

pub fn __getitem__(&self, key: String) -> PyResult<String> {
self.get(key)
}
}

impl Headers {
Expand Down

0 comments on commit 13e9f13

Please sign in to comment.