Skip to content

Commit 15b00cb

Browse files
committed
Added server parameter to Request
1 parent fdf66bf commit 15b00cb

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

adafruit_httpserver/request.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88
"""
99

1010
try:
11-
from typing import Dict, Tuple, Union
11+
from typing import Dict, Tuple, Union, TYPE_CHECKING
1212
from socket import socket
1313
from socketpool import SocketPool
14+
15+
if TYPE_CHECKING:
16+
from .server import Server
1417
except ImportError:
1518
pass
1619

@@ -23,6 +26,11 @@ class Request:
2326
It is passed as first argument to all route handlers.
2427
"""
2528

29+
server: "Server"
30+
"""
31+
Server object that received the request.
32+
"""
33+
2634
connection: Union["SocketPool.Socket", "socket.socket"]
2735
"""
2836
Socket object used to send and receive data on the connection.
@@ -72,10 +80,12 @@ class Request:
7280

7381
def __init__(
7482
self,
83+
server: "Server",
7584
connection: Union["SocketPool.Socket", "socket.socket"],
7685
client_address: Tuple[str, int],
7786
raw_request: bytes = None,
7887
) -> None:
88+
self.server = server
7989
self.connection = connection
8090
self.client_address = client_address
8191
self.raw_request = raw_request

adafruit_httpserver/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def _receive_request(
132132
if not header_bytes:
133133
return None
134134

135-
request = Request(sock, client_address, header_bytes)
135+
request = Request(self, sock, client_address, header_bytes)
136136

137137
content_length = int(request.headers.get("Content-Length", 0))
138138
received_body_bytes = request.body

0 commit comments

Comments
 (0)