Skip to content

Commit 523f759

Browse files
committed
Support passing headers for authorized calls etc
1 parent 5b3ba12 commit 523f759

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "recnetpy"
7-
version = "0.1.37"
7+
version = "0.1.38"
88
authors = [
99
{ name="RecNetBot Development"}
1010
]

src/recnetpy/rest/request.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ class Request(ThreadTask[Response]):
2424
method: str
2525
params: Optional[Dict]
2626
body: Optional[Dict]
27+
headers: Optional[Dict]
2728

28-
def __init__(self, client: ClientSession, method: str, url: str, params: Optional[Dict] = None, body: Optional[Dict] = None) -> None:
29+
def __init__(self, client: ClientSession, method: str, url: str, params: Optional[Dict] = None, body: Optional[Dict] = None, headers: Optional[Dict] = None) -> None:
2930
super().__init__()
3031
self.client = client
3132
self.method = method
3233
self.url = url
3334
self.params = params
3435
self.body = body
36+
self.headers = headers
3537

3638
async def run(self) -> Response:
3739
"""
@@ -40,7 +42,7 @@ async def run(self) -> Response:
4042
4143
@return: A response object containing the fetched data.
4244
"""
43-
async with self.client.request(self.method, self.url, data = self.body, params = self.params) as response:
45+
async with self.client.request(self.method, self.url, data = self.body, params = self.params, headers = self.headers) as response:
4446
data = await parse_response(response)
4547
return Response(response.status, response.ok, data)
4648

src/recnetpy/rest/route_builder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def __init__(self, client: 'HTTPClient', base: str) -> None:
2020
self.base = base
2121
self.client = client
2222

23-
async def make_request(self, method: str, params: Optional[Dict] = None, body: Optional[Dict] = None) -> 'Response':
23+
async def make_request(self, method: str, params: Optional[Dict] = None, body: Optional[Dict] = None, headers: Optional[Dict] = None) -> 'Response':
2424
"""
2525
Joins the route components into a url, and constructs
2626
a request object that is processed by the http client.
@@ -31,7 +31,7 @@ async def make_request(self, method: str, params: Optional[Dict] = None, body: O
3131
@return: The response from the request.
3232
"""
3333
url = self.base + "/".join(self.route)
34-
request = Request(self.client.session, method, url, params, body)
34+
request = Request(self.client.session, method, url, params, body, headers)
3535
return await self.client.push(request)
3636

3737
def __getattr__(self, name: str):

0 commit comments

Comments
 (0)