Skip to content

sse keepalive #15

Description

@Fak3
import asyncio
from django.http import StreamingHttpResponse

async def sse_stream(request):
    async def event_stream():
        # Example: send a keepalive ping every 15 seconds
        while True:
            yield f": keepalive \n\n"
            await asyncio.sleep(15)

    response = StreamingHttpResponse(event_stream(), content_type='text/event-stream')
    response['Cache-Control'] = 'no-cache'
    response['X-Accel-Buffering'] = 'no' # Disable Nginx buffering
    return response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions