Skip to content

Unauthorized websocket #229

@Korijn

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions