Skip to content

Commit

Permalink
Stop running request middleware upon connection.
Browse files Browse the repository at this point in the history
This change deserves a more thorough explanation.  All currently
released versions of Django are based around the concept of receiving a
request and immediately dispatching a response.

WebSocket connections don't follow this convention, and the `request` hangs
around for long periods of time.  As such, things like `request.user` don't
really make sense as a user may login, then logout, then login again all
within the life of a single request.

Given that the concepts applied in Django are based upon a premise that
doesn't hold true for WebSockets (that a request is short-lived), it
doesn't make sense to apply those concepts in django-ddp.
  • Loading branch information
tysonclugg committed Jul 21, 2015
1 parent d358ce4 commit e7b38b8
Showing 1 changed file with 1 addition and 12 deletions.
13 changes: 1 addition & 12 deletions dddp/websocket.py
Expand Up @@ -107,7 +107,6 @@ class DDPWebSocketApplication(geventwebsocket.WebSocketApplication):
support = None
connection = None
subs = None
request = None
remote_ids = None
base_handler = BaseHandler()

Expand Down Expand Up @@ -312,21 +311,11 @@ def recv_connect(self, version=None, support=None, session=None):
elif version not in support:
self.error('Client version/support mismatch.')
else:
self.request = WSGIRequest(self.ws.environ)
# Apply request middleware (so we get request.user and other attrs)
# pylint: disable=protected-access
if self.base_handler._request_middleware is None:
self.base_handler.load_middleware()
for middleware_method in self.base_handler._request_middleware:
response = middleware_method(self.request)
if response:
raise ValueError(response)
this.request = WSGIRequest(self.ws.environ)
this.ws = self
this.request = self.request
this.send = self.send
this.reply = self.reply
this.error = self.error
this.request.session.save()

from dddp.models import Connection
cur = connection.cursor()
Expand Down

0 comments on commit e7b38b8

Please sign in to comment.