Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ alabaster==0.7.16
astroid==2.15.8
babel==2.18.0
balderhub-unit==0.0.1b0
balderhub-url==0.0.1b0
balderplugin-junit==0.0.3
baldertest==0.2.0
certifi==2026.2.25
Expand Down
8 changes: 6 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,17 @@ packages =
balderhub.http
balderhub.http.lib
balderhub.http.lib.scenario_features
balderhub.http.lib.scenario_features.client
balderhub.http.lib.scenario_features.server
balderhub.http.lib.setup_features
balderhub.http.lib.setup_features.client
balderhub.http.lib.setup_features.server
balderhub.http.lib.utils
balderhub.http.scenarios
balderhub.http.setups

install_requires =
baldertest
balderhub-url
balderhub-auth
python_requires = >=3.10
package_dir =
=src
Expand Down
6 changes: 0 additions & 6 deletions src/balderhub/http/lib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +0,0 @@
# TODO add classes / functions from module (if any)
# TODO delete module if it has no sub elements

__all__ = [

]
7 changes: 4 additions & 3 deletions src/balderhub/http/lib/scenario_features/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# TODO add classes / functions from module (if any)
# TODO delete module if it has no sub elements
from . import client
from . import server

__all__ = [

"client",
"server"
]
Empty file.
Empty file.
7 changes: 4 additions & 3 deletions src/balderhub/http/lib/setup_features/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# TODO add classes / functions from module (if any)
# TODO delete module if it has no sub elements
from . import client
from . import server

__all__ = [

"client",
"server"
]
Empty file.
Empty file.
9 changes: 6 additions & 3 deletions src/balderhub/http/lib/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# TODO add classes / functions from module (if any)
# TODO delete module if it has no sub elements
from .http_method import HttpMethod
from .http_request_message import HttpRequestMessage
from .response import Response

__all__ = [

"HttpMethod",
"HttpRequestMessage",
"Response",
]
30 changes: 30 additions & 0 deletions src/balderhub/http/lib/utils/functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import requests

from balderhub.url.lib.utils import Url


from .response import Response

def convert_requests_response(response: requests.Response) -> Response:
"""
Converts a `requests.Response` object into the BalderHub `Response` object.

:param response: A `requests.Response` object that contains metadata, content,
and history of the HTTP request/response cycle.
:return: A transformed `Response` object containing the status code, URL,
content, and processed history of the `requests.Response`.
"""
history = []
for cur_history in response.history:
history.append(
Response(
status_code=cur_history.status_code,
url=Url(cur_history.url),
content=cur_history.content)
)
return Response(
status_code=response.status_code,
url=Url(response.url),
history=history,
content=response.content
)
14 changes: 14 additions & 0 deletions src/balderhub/http/lib/utils/http_method.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from enum import Enum

class HttpMethod(Enum):
"""
This enum describes all common HTTP methods supported by BalderHub.
"""
GET = "GET"
POST = "POST"
PUT = "PUT"
PATCH = "PATCH"
DELETE = "DELETE"
HEAD = "HEAD"
OPTIONS = "OPTIONS"
TRACE = "TRACE"
44 changes: 44 additions & 0 deletions src/balderhub/http/lib/utils/http_request_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from balderhub.url.lib.utils import Url

from balderhub.http.lib.utils import HttpMethod


class HttpRequestMessage:
"""Represents an HTTP request message consisting of a URL and an HTTP method.

This class encapsulates the essential parts of an HTTP request.

:param url: The target URL for the HTTP request.
:param method: The HTTP method to be used for the request.
"""

def __init__(self, url: Url, method: HttpMethod):
"""Initialize the HTTP request message.

:param url: The target URL for the HTTP request.
:param method: The HTTP method to be used for the request.
"""
self._url = url
self._method = method

def __eq__(self, other):
"""Check equality with another object.

Two :class:`HttpRequestMessage` instances are considered equal if they have the same URL and HTTP method.

:param other: The object to compare with.
:return: ``True`` if both instances have the same URL and method, ``False`` otherwise.
"""
if not isinstance(other, HttpRequestMessage):
return False
return self._url == other._url and self._method == other._method

@property
def url(self) -> Url:
"""The target URL for the HTTP request."""
return self._url

@property
def method(self) -> HttpMethod:
"""The HTTP method to be used for the request."""
return self._method
30 changes: 30 additions & 0 deletions src/balderhub/http/lib/utils/response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from __future__ import annotations
import dataclasses

from balderhub.url.lib.utils import Url



@dataclasses.dataclass
class Response:
"""
Represents an HTTP response received from a request made to a specific URL.

This class encapsulates the details of an HTTP response, including the status code,
the URL from which the response was received, the content of the response, and the
history of any preceding responses (e.g., in cases of redirects or retries).

:ivar status_code: Status code returned by the server.
:type status_code: int
:ivar url: The URL from which the response was received.
:type url: Url
:ivar content: The raw binary content of the response.
:type content: bytes
:ivar history: List of preceding Response objects that represent the redirection
or retry history leading to this response. Defaults to an empty list.
:type history: list[Response]
"""
status_code: int
url: Url
content: bytes
history: list[Response] = dataclasses.field(default_factory=list)
6 changes: 0 additions & 6 deletions src/balderhub/http/scenarios/__init__.py

This file was deleted.

6 changes: 0 additions & 6 deletions src/balderhub/http/setups/__init__.py

This file was deleted.

Loading