fanout / django-eventstream

Server-Sent Events for Django
MIT License
638 stars 84 forks source link

Is it possible to use gzip compression? #67

Closed paolodina closed 3 years ago

paolodina commented 3 years ago

Hello, the application where I'm using django-eventstream sends every few seconds a good amount of text data using send_event. I wonder if it'd be possible to send compressed messages to the clients instead of full responses (~100kb).

I need to reduce the outgoing bandwidth, thanks for any advice you could give.

paolodina commented 3 years ago

I'd also consider to use something in front of hypercorn if this could help. But have no idea what to do.

jkarneges commented 3 years ago

Maybe put Nginx in front?

paolodina commented 3 years ago

@jkarneges I thought it could have be managed by django-eventstream, but yes, I'll try to put caddy as a reverse proxy enabling gzip server side, good idea.

jkarneges commented 3 years ago

Yeah for now a proxy may be easiest.

For gzip to be done in the actual Django app, I think it would be best done as middleware. This should be possible by writing ASGI middleware code. The Starlette framework appears to have a gzip middleware, although I don't know how portable it is.

Long term I hope all normal Django middlware will work with ASGI, but that could be awhile.