Skip to content

Commit

Permalink
Merge pull request #9 from feteu/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
feteu authored Dec 27, 2024
2 parents 54f32ae + 8f448e8 commit 11802ba
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
10 changes: 8 additions & 2 deletions asgi_request_duration/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
"""
ASGI Request Duration Package
This package provides middleware and utilities to measure and log the duration of HTTP requests in ASGI applications.
"""

from asgi_request_duration.context import REQUEST_DURATION_CTX_KEY, request_duration_ctx_var
from asgi_request_duration.exceptions import InvalidHeaderNameException, PrecisionValueOutOfRangeException
from asgi_request_duration.filters import RequestDurationFilter
from asgi_request_duration.middleware import RequestDurationMiddleware

__all__ = [
__all__ = (
"InvalidHeaderNameException",
"PrecisionValueOutOfRangeException",
"REQUEST_DURATION_CTX_KEY",
"request_duration_ctx_var",
"RequestDurationFilter",
"RequestDurationMiddleware",
]
)
16 changes: 8 additions & 8 deletions asgi_request_duration/constants.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import re

_DEFAULT_EXCLUDED_PATHS = []
_DEFAULT_HEADER_NAME = "X-Request-Duration"
_DEFAULT_PRECISION = 6
_DEFAULT_SKIP_VALIDATE_HEADER_NAME = False
_DEFAULT_SKIP_VALIDATE_PRECISION = False
_HEADER_NAME_PATTERN = re.compile(r"^[a-zA-Z0-9][a-zA-Z0-9-_]*$")
_PRECISION_MAX = 17
_PRECISION_MIN = 0
_DEFAULT_EXCLUDED_PATHS: list = []
_DEFAULT_HEADER_NAME: str = "X-Request-Duration"
_DEFAULT_PRECISION: int = 6
_DEFAULT_SKIP_VALIDATE_HEADER_NAME: bool = False
_DEFAULT_SKIP_VALIDATE_PRECISION: bool = False
_HEADER_NAME_PATTERN: re.Pattern = re.compile(r"^[a-zA-Z0-9][a-zA-Z0-9-_]*$")
_PRECISION_MAX: int = 17
_PRECISION_MIN: int = 0
8 changes: 4 additions & 4 deletions asgi_request_duration/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
_PRECISION_MIN,
)

def validate_header_name(skip=_DEFAULT_SKIP_VALIDATE_HEADER_NAME) -> callable:
def validate_header_name(skip: bool =_DEFAULT_SKIP_VALIDATE_HEADER_NAME) -> callable:
"""
Decorator to validate the header name against a pattern.
Expand All @@ -23,7 +23,7 @@ def validate_header_name(skip=_DEFAULT_SKIP_VALIDATE_HEADER_NAME) -> callable:
Raises:
InvalidHeaderNameException: If the header name is invalid.
"""
def decorator(func)-> callable:
def decorator(func: callable)-> callable:
def wrapper(*args, **kwargs) -> callable:
if not skip:
header_name = kwargs.get('header_name', _DEFAULT_HEADER_NAME)
Expand All @@ -33,7 +33,7 @@ def wrapper(*args, **kwargs) -> callable:
return wrapper
return decorator

def validate_precision(skip=_DEFAULT_SKIP_VALIDATE_PRECISION)-> callable:
def validate_precision(skip: bool =_DEFAULT_SKIP_VALIDATE_PRECISION)-> callable:
"""
Decorator to validate the precision value.
Expand All @@ -47,7 +47,7 @@ def validate_precision(skip=_DEFAULT_SKIP_VALIDATE_PRECISION)-> callable:
Raises:
PrecisionValueOutOfRangeException: If the precision value is out of range.
"""
def decorator(func) -> callable:
def decorator(func: callable) -> callable:
def wrapper(*args, **kwargs) -> callable:
if not skip:
precision = kwargs.get('precision', _DEFAULT_PRECISION)
Expand Down
4 changes: 2 additions & 2 deletions asgi_request_duration/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class InvalidHeaderNameException(Exception):
This class represents an error that occurs when an invalid header name is provided.
It provides a custom description to inform the user about the invalid header name.
"""
description = (
description: str = (
"Invalid header name provided. "
"Please ensure that the header name is correct and try again."
)
Expand All @@ -22,7 +22,7 @@ class PrecisionValueOutOfRangeException(ValueError):
This class represents an error that occurs when a precision value is out of the allowed range.
It provides a custom description to inform the user about the out-of-range precision value.
"""
description = (
description: str = (
"Precision value is out of range. "
"Please ensure that the precision value is within the allowed range."
)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "asgi-request-duration"
version = "1.0.1"
version = "1.0.2"
description = "A asgi middleware to measure the request duration"
authors = ["Fabio Greco <fabio.greco.github@gmail.com>"]
maintainers = ["Fabio Greco <fabio.greco.github@gmail.com>"]
Expand Down

0 comments on commit 11802ba

Please sign in to comment.