diff --git a/polyapi/__init__.py b/polyapi/__init__.py index 7935843..0d811a3 100644 --- a/polyapi/__init__.py +++ b/polyapi/__init__.py @@ -1,5 +1,6 @@ import os import sys +import copy import truststore from typing import Any, Optional, overload, Literal from typing_extensions import TypedDict @@ -22,6 +23,7 @@ class PolyCustomDict(TypedDict, total=False): executionApiKey: Optional[str] responseStatusCode: int responseContentType: Optional[str] + responseHeaders: Dict[str, str] class _PolyCustom: @@ -31,6 +33,7 @@ def __init__(self): "executionApiKey": None, "responseStatusCode": 200, "responseContentType": None, + "responseHeaders": {}, } self._execution_id_locked = False @@ -63,6 +66,9 @@ def __getitem__(self, key: Literal["responseStatusCode"]) -> int: ... @overload def __getitem__(self, key: Literal["responseContentType"]) -> Optional[str]: ... + + @overload + def __getitem__(self, key: Literal["responseHeaders"]) -> Dict[str, str]: ... def __getitem__(self, key: str) -> Any: return self.get(key) @@ -75,6 +81,9 @@ def __setitem__(self, key: Literal["responseStatusCode"], value: int) -> None: . @overload def __setitem__(self, key: Literal["responseContentType"], value: Optional[str]) -> None: ... + + @overload + def __setitem__(self, key: Literal["responseHeaders"], value: Dict[str, str]) -> None: ... def __setitem__(self, key: str, value: Any) -> None: self.set_once(key, value) @@ -84,7 +93,7 @@ def __repr__(self) -> str: def copy(self) -> '_PolyCustom': new = _PolyCustom() - new._internal_store = self._internal_store.copy() + new._internal_store = copy.deepcopy(self._internal_store) new._execution_id_locked = self._execution_id_locked return new diff --git a/polyapi/webhook.py b/polyapi/webhook.py index 855c300..b27987d 100644 --- a/polyapi/webhook.py +++ b/polyapi/webhook.py @@ -65,6 +65,7 @@ async def handleEvent(data): "data": resp, "statusCode": polyCustom.get("responseStatusCode", 200), "contentType": polyCustom.get("responseContentType", None), + "headers": polyCustom.get("responseHeaders", {{}}), }}, }}, namespace="/events") diff --git a/pyproject.toml b/pyproject.toml index f5c2514..93e189b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ requires = ["setuptools>=61.2", "wheel"] [project] name = "polyapi-python" -version = "0.3.7.dev4" +version = "0.3.7.dev5" description = "The Python Client for PolyAPI, the IPaaS by Developers for Developers" authors = [{ name = "Dan Fellin", email = "dan@polyapi.io" }] dependencies = [