Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate BaseHTTPMiddleware #1898

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 6 additions & 1 deletion docs/middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ The following arguments are supported:

## BaseHTTPMiddleware

!!! warning
The `BaseHTTPMiddleware` is deprecated since version `0.22.0`.

Please refer to [Pure ASGI Middleware](#pure-asgi-middleware) for the recommended way to implement middleware.

An abstract class that allows you to write ASGI middleware against a request/response
interface.

Expand Down Expand Up @@ -569,7 +574,7 @@ import time
class MonitoringMiddleware:
def __init__(self, app):
self.app = app

async def __call__(self, scope, receive, send):
start = time.time()
try:
Expand Down
8 changes: 8 additions & 0 deletions starlette/middleware/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import typing
import warnings

import anyio

Expand All @@ -12,6 +13,13 @@
]
T = typing.TypeVar("T")

warnings.warn(
"The 'BaseHTTPMiddleware' is deprecated, and will be removed in version 1.0.0. "
"Refer to https://www.starlette.io/middleware/#pure-asgi-middleware to learn how to create middlewares.\n" # noqa: E501
"If you need help, please create a discussion on: https://github.com/encode/starlette/discussions.", # noqa: E501
DeprecationWarning,
)


class BaseHTTPMiddleware:
def __init__(
Expand Down