An abstract middleware for Starlette
Project description
Abstract Middleware for Starlette
AbstractHTTPMiddleware is replacing the original Starlette's BaseHTTPMiddleware.
In the original BaseHTTPMiddleware a RuntimeError with message No response returned is raised when two or more middlewares inheriting from the BaseHTTPMiddleware were used in the middleware stack following each other.
The new AbstractHTTPMiddleware is simply handling a situation when client closes connection early, during the original request is processing in endpoint. Normally an anyio.EndOfStream would be raised, causing a RuntimeError exception with message No response returned. This situation is fully logged and handled by returning a new response with status_code=499 and content='Client closed connection'.
Instalation
pip install starlette_abstract
Simple Example
from starlette_abstract.middleware import AbstractHTTPMiddleware, RequestResponseEndpoint
from starlette.requests import Request
from starlette.responses import Response
class MyCustomMiddleware(AbstractHTTPMiddleware):
async def dispatch(self, request: Request, call_next: RequestResponseEndpoint) -> Response:
# do something with request
response = await call_next(request)
# do something with response
return response
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file starlette_abstract-0.0.1.tar.gz.
File metadata
- Download URL: starlette_abstract-0.0.1.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c19121f26c0ab0f7258f55fb6ce0147b1061d09fde58186a4eb8cda61785cb7
|
|
| MD5 |
0c6045608fc79f93a1b5a4399350b2c3
|
|
| BLAKE2b-256 |
27b86e87b2959ea1b0286d26f48b44a7582357c984a7b5777a1a9d6413cf7110
|
File details
Details for the file starlette_abstract-0.0.1-py3-none-any.whl.
File metadata
- Download URL: starlette_abstract-0.0.1-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
00e36c09625b0f78a59f1cc3608ac4490150c5fbd76a504cd8db5e54a2f49e45
|
|
| MD5 |
677c58a5cbc2d178c6938cca6bb3a674
|
|
| BLAKE2b-256 |
996b8686bd98c209a07455b23b9d2d5b2cb8cbaa0f6966cc56683f3f8f0089f6
|