pgjones / hypercorn

Hypercorn is an ASGI and WSGI Server based on Hyper libraries and inspired by Gunicorn.
MIT License
1.18k stars 105 forks source link

Add write_timeout option #262

Closed jordanlibrande closed 3 weeks ago

jordanlibrande commented 3 weeks ago

This adds a write_timeout option, similar to existing option read_timeout, but for timeout while writing responses.

The usecase is to detect and fail early if a client doesn't promptly read & ack response packets. (Either regular client, or intentionally malicious client doing a "slow read" attack).

In order to implement it properly and have identical semantics to read_timeout, I needed to refactor to switch sending to be chunk-based.

I'm new to this codebase, feedback would be great!

The other things we could do:

jordanlibrande commented 3 weeks ago

I was able to work around this I think satisfactorily with custom ASGI middleware, closing the PR for now