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
4 changes: 3 additions & 1 deletion sdk/python/src/datastar_py/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
class DatastarResponse(_StreamingHttpResponse):
"""Respond with 0..N `DatastarEvent`s"""

default_headers: dict[str, str] = SSE_HEADERS.copy()

def __init__(
self,
content: DatastarEvents = None,
Expand All @@ -34,7 +36,7 @@ def __init__(
status = status or 204
content = tuple()
else:
headers = {**SSE_HEADERS, **(headers or {})}
headers = {**self.default_headers, **(headers or {})}
if isinstance(content, DatastarEvent):
content = (content,)
super().__init__(content, status=status, headers=headers)
Expand Down
4 changes: 3 additions & 1 deletion sdk/python/src/datastar_py/litestar.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
class DatastarResponse(Stream):
"""Respond with 0..N `DatastarEvent`s"""

default_headers: dict[str, str] = SSE_HEADERS.copy()

def __init__(
self,
content: DatastarEvents = None,
Expand All @@ -40,7 +42,7 @@ def __init__(
status_code = status_code or 204
content = tuple()
else:
headers = {**SSE_HEADERS, **(headers or {})}
headers = {**self.default_headers, **(headers or {})}
if isinstance(content, DatastarEvent):
content = (content,)
super().__init__(
Expand Down
4 changes: 3 additions & 1 deletion sdk/python/src/datastar_py/quart.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
class DatastarResponse(Response):
"""Respond with 0..N `DatastarEvent`s"""

default_headers: dict[str, str] = SSE_HEADERS.copy()

def __init__(
self,
content: DatastarEvents = None,
Expand All @@ -31,7 +33,7 @@ def __init__(
if not content:
status = status or 204
else:
headers = {**SSE_HEADERS, **(headers or {})}
headers = {**self.default_headers, **(headers or {})}
super().__init__(content, status=status, headers=headers)
if isgenerator(content) or isasyncgen(content):
self.timeout = None
Expand Down
6 changes: 5 additions & 1 deletion sdk/python/src/datastar_py/sanic.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@


class DatastarResponse(HTTPResponse):
default_headers: dict[str, str] = SSE_HEADERS.copy()

def __init__(
self,
content: DatastarEvent | Collection[DatastarEvent] | None = None,
Expand All @@ -28,7 +30,9 @@ def __init__(
) -> None:
if not content:
status = status or 204
super().__init__(content, status=status or 200, headers={**SSE_HEADERS, **(headers or {})})
super().__init__(
content, status=status or 200, headers={**self.default_headers, **(headers or {})}
)

async def send(
self,
Expand Down
4 changes: 3 additions & 1 deletion sdk/python/src/datastar_py/starlette.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
class DatastarResponse(_StreamingResponse):
"""Respond with 0..N `DatastarEvent`s"""

default_headers: dict[str, str] = SSE_HEADERS.copy()

def __init__(
self,
content: DatastarEvents = None,
Expand All @@ -35,7 +37,7 @@ def __init__(
content = tuple()
else:
status_code = status_code or 200
headers = {**SSE_HEADERS, **(headers or {})}
headers = {**self.default_headers, **(headers or {})}
if isinstance(content, DatastarEvent):
content = (content,)
super().__init__(content, status_code=status_code, headers=headers, background=background)
Expand Down