From 2dd7f589eb970916a308095e4e9de1cc9dd72188 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Wed, 9 Sep 2015 21:25:36 -0500 Subject: [PATCH] Lowercase request GET/POST etc. --- channels/decorators.py | 12 ++++++------ channels/request.py | 16 ++++++++-------- docs/message-standards.rst | 8 ++++---- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/channels/decorators.py b/channels/decorators.py index bc5f116..03a4ecc 100644 --- a/channels/decorators.py +++ b/channels/decorators.py @@ -26,17 +26,17 @@ def http_session(func): """ @functools.wraps(func) def inner(message, *args, **kwargs): - if "COOKIES" not in message.content and "GET" not in message.content: - raise ValueError("No COOKIES or GET sent to consumer; this decorator can only be used on messages containing at least one.") + if "cookies" not in message.content and "get" not in message.content: + raise ValueError("No cookies or get sent to consumer; this decorator can only be used on messages containing at least one.") # Make sure there's a session key session_key = None - if "GET" in message.content: + if "get" in message.content: try: - session_key = message.content['GET'].get("session_key", [])[0] + session_key = message.content['get'].get("session_key", [])[0] except IndexError: pass - if "COOKIES" in message.content and session_key is None: - session_key = message.content['COOKIES'].get(settings.SESSION_COOKIE_NAME) + if "cookies" in message.content and session_key is None: + session_key = message.content['cookies'].get(settings.SESSION_COOKIE_NAME) # Make a session storage if session_key: session_engine = import_module(settings.SESSION_ENGINE) diff --git a/channels/request.py b/channels/request.py index dafcf49..1c975ef 100644 --- a/channels/request.py +++ b/channels/request.py @@ -10,10 +10,10 @@ def encode_request(request): """ # TODO: More stuff value = { - "GET": dict(request.GET.lists()), - "POST": dict(request.POST.lists()), - "COOKIES": request.COOKIES, - "META": {k: v for k, v in request.META.items() if not k.startswith("wsgi")}, + "get": dict(request.GET.lists()), + "post": dict(request.POST.lists()), + "cookies": request.COOKIES, + "meta": {k: v for k, v in request.META.items() if not k.startswith("wsgi")}, "path": request.path, "path_info": request.path_info, "method": request.method, @@ -27,10 +27,10 @@ def decode_request(value): Decodes a request JSONish value to a HttpRequest object. """ request = HttpRequest() - request.GET = CustomQueryDict(value['GET']) - request.POST = CustomQueryDict(value['POST']) - request.COOKIES = value['COOKIES'] - request.META = value['META'] + request.GET = CustomQueryDict(value['get']) + request.POST = CustomQueryDict(value['post']) + request.COOKIES = value['cookies'] + request.META = value['meta'] request.path = value['path'] request.method = value['method'] request.path_info = value['path_info'] diff --git a/docs/message-standards.rst b/docs/message-standards.rst index 405b23c..722e218 100644 --- a/docs/message-standards.rst +++ b/docs/message-standards.rst @@ -34,10 +34,10 @@ Standard channel name is ``http.request``. Contains the following keys: -* GET: List of (key, value) tuples of GET variables (keys and values are strings) -* POST: List of (key, value) tuples of POST variables (keys and values are strings) -* COOKIES: Dict of cookies as {cookie_name: cookie_value} (names and values are strings) -* META: Dict of HTTP headers and info as defined in the Django Request docs (names and values are strings) +* get: List of (key, value) tuples of GET variables (keys and values are strings) +* post: List of (key, value) tuples of POST variables (keys and values are strings) +* cookies: Dict of cookies as {cookie_name: cookie_value} (names and values are strings) +* meta: Dict of HTTP headers and info as defined in the Django Request docs (names and values are strings) * path: String, full path to the requested page, without query string or domain * path_info: String, like ``path`` but without any script prefix. Often just ``path``. * method: String, upper-cased HTTP method