Skip to content

Commit

Permalink
Removed automatic routing of HTTP handler in ProtocolType Router. (#1891
Browse files Browse the repository at this point in the history
)
  • Loading branch information
carltongibson committed Aug 4, 2022
1 parent 64b4346 commit 3542845
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Next Release (will be 4.0)
* Minimum Django version is now Django 3.2.
* Added compatibility with Django 4.1.
* Removed deprecated static files handling in favor of ``django.contrib.staticfiles``.
* Removed deprecated automatic routing of ``http`` protocol handler in ProtocolTypeRouter.
You must explicitly register the ``http`` handler in your application.

3.0.5 (2022-06-24)
------------------
Expand Down
6 changes: 0 additions & 6 deletions channels/routing.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import importlib
import warnings

from asgiref.compatibility import guarantee_single_callable
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.urls.exceptions import Resolver404
from django.urls.resolvers import URLResolver

from channels.http import AsgiHandler

"""
All Routing instances inside this file are also valid ASGI applications - with
new Channels routing, whatever you end up with as the top level object is just
Expand Down Expand Up @@ -59,9 +56,6 @@ class ProtocolTypeRouter:

def __init__(self, application_mapping):
self.application_mapping = application_mapping
if "http" not in self.application_mapping:
warnings.warn(DEPRECATION_MSG, DeprecationWarning, stacklevel=2)
self.application_mapping["http"] = AsgiHandler()

async def __call__(self, scope, receive, send):
if scope["type"] in self.application_mapping:
Expand Down
6 changes: 0 additions & 6 deletions tests/test_deprecations.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import pytest

from channels.http import AsgiHandler
from channels.routing import ProtocolTypeRouter


def test_automatical_http_protocol_registration_deprecation():
with pytest.warns(DeprecationWarning):
ProtocolTypeRouter({})


def test_asgi_handler_deprecation():
Expand Down
4 changes: 0 additions & 4 deletions tests/test_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from django.core.exceptions import ImproperlyConfigured
from django.urls import path, re_path

from channels.http import AsgiHandler
from channels.routing import ChannelNameRouter, ProtocolTypeRouter, URLRouter


Expand Down Expand Up @@ -34,9 +33,6 @@ async def test_protocol_type_router():
)
assert await router({"type": "websocket"}, None, None) == "ws"
assert await router({"type": "http"}, None, None) == "http"
# Test defaulting to AsgiHandler
router = ProtocolTypeRouter({"websocket": MockApplication(return_value="ws")})
assert isinstance(router.application_mapping["http"], AsgiHandler)
# Test an unmatched type
with pytest.raises(ValueError):
await router({"type": "aprs"}, None, None)
Expand Down

0 comments on commit 3542845

Please sign in to comment.