Skip to content

Unauthorized websocket #229

Closed
Closed

Description

@Korijn

I've been trying to implement ConnectionRefused exception messaging to signal to my clients why their connections are refused.

However, my clients use the socket.io library with the websocket transport only (polling transport disabled). And it seems that that triggers the following codepath:

async def make_response(status, headers, payload, environ):
    headers = [(h[0].encode('utf-8'), h[1].encode('utf-8')) for h in headers]
    if environ['asgi.scope']['type'] == 'websocket':
        if status.startswith('200 '):
            await environ['asgi.send']({'type': 'websocket.accept',
                                        'headers': headers})
        else:
            await environ['asgi.send']({'type': 'websocket.close'})   # <---- codepath ends here
        return

    await environ['asgi.send']({'type': 'http.response.start',
                                'status': int(status.split(' ')[0]),
                                'headers': headers})
    await environ['asgi.send']({'type': 'http.response.body',
                                'body': payload})   # <---- this contains my connection refused message

And the payload is never returned to the client.

Does this mean that it only works with the socket.io polling transport?

Activity

  1. miguelgrinberg commented on Jun 15, 2021

    @miguelgrinberg
    Owner

    The websocket.close event in ASGI does not allow a payload to be included.

    I'll have to think about this to see if there is any way within the ASGI and Socket.IO rules to pass on an error message with a rejection.

  2. Repository owner locked and limited conversation to collaborators on Jun 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions