From 435b2dd58a8605d1600886a2aff3268a32b6735e Mon Sep 17 00:00:00 2001 From: Philipp Kilian Date: Thu, 23 May 2024 15:02:24 +0200 Subject: [PATCH] api: fix missing POST headers if an asset is sent --- CHANGELOG.md | 7 ++++++- b3lb/rest/classes/api.py | 17 ++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 68b9747..7427208 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,16 @@ # ChangeLog +## 3.2.2 - 2024-05-23 + +Fixes: +- fix missing specific POST Header when an asset is sent + ## 3.2.1 - 2024-05-21 Changes: - adjust to BBB 2.7.8 API changes - forbid POST request for `join` endpoint () - - adjustments for POST headers are already handled + - adjustments for POST headers are already handled - meeting name check: - add check for meeting name length for faster response without sending a request to backend systems - meeting name length must be between 2 and 256 characters as given by BBB API restrictions diff --git a/b3lb/rest/classes/api.py b/b3lb/rest/classes/api.py index fb3ee30..a6c8479 100644 --- a/b3lb/rest/classes/api.py +++ b/b3lb/rest/classes/api.py @@ -56,9 +56,22 @@ class ClientB3lbRequest: node: Union[Node, None] secret: Union[Secret, None] state: str + has_assets: bool ENDPOINTS_PASS_THROUGH: List[str] ENDPOINTS: Dict[str, Any] + #### Class functions + async def _check_post_headers(self) -> Dict[str, Any]: + if not self.has_assets: + # request wasn't manipulated by B3LB + return self.request.headers + + # An asset was added by B3LB + headers = dict(self.request.headers.copy()) + headers["Content-Type"] = "application/xml" + headers["Content-Length"] = str(len(self.body)) + return headers + #### Asynchronous BBB Endpoints async def create(self) -> HttpResponse: """ @@ -234,7 +247,7 @@ async def pass_through(self) -> HttpResponse: await self.set_node_by_meeting_id() async with ClientSession() as session: if self.request.method == "POST": - async with session.post(await sync_to_async(self.get_node_endpoint_url_encoded)(), data=self.body) as res: + async with session.post(await sync_to_async(self.get_node_endpoint_url_encoded)(), data=self.body, headers=await self._check_post_headers()) as res: return HttpResponse(await res.text(), status=res.status, content_type=res.headers.get('content-type', cst.CONTENT_TYPE)) else: async with session.get(await sync_to_async(self.get_node_endpoint_url_encoded)()) as res: @@ -367,6 +380,7 @@ def check_parameters(self, meeting: Meeting = None, created: bool = False): else: self.body = f'' self.request.method = "POST" + self.has_assets = True # check if records are enabled if self.secret.is_record_enabled: @@ -528,6 +542,7 @@ async def set_secret_by_slug_and_slug_id(self, slug: str, sub_id: int): ## INIT ## def __init__(self, request: HttpRequest, endpoint: str): + self.has_assets = False self.request = request self.endpoint = endpoint self.parameters = {}