flask-uwsgi-websocket icon indicating copy to clipboard operation
flask-uwsgi-websocket copied to clipboard

Using request context with other decorators

Open rosensama opened this issue 7 years ago • 0 comments

Under your Advanced Usage in the README docs it mentions how to expose the request context in a websocket handler using:

with app.request_context(ws.environ):

Is there a recommended way to do this so that the request context is available to other decorators? Say I have a @login_required decorator that invokes a check for a cookie or header? Should I roll my own decorator that combines the two? Do I need to unroll the @login_required decorator to occur as inline code after I've exposed the request context?

@ws.route('sockets/chat/<string:channel_name>')
@login_required
def websocket_chat(socket, channel_name):

Where @login_required expects to find the request context.

rosensama avatar Nov 24 '17 15:11 rosensama