Skip to content

pywebsocket3 vs. websockets #28863

@foolip

Description

@foolip

We currently use two different Python libraries for WebSockets:

  • pywebsocket3. This is what is used in wptserve and websockets/handlers/ to test the WebSockets protocol itself.
  • websockets, recently introduced for testing WebDriver BiDi. It's designed for using WebSockets rather than testing it, and is probably not as easy to use for sending deliberately invalid data.

Both are vendored into tools/third_party/.

Note that even with pywebsocket3 we're using "private" APIs:

# TODO: We are using "private" methods of pywebsocket. We might want to
# refactor pywebsocket to expose those methods publicly. Also, _get_origin
# _check_version _set_protocol _parse_extensions and a large part of do_handshake
# are identical with hybi handshake. We need some refactoring to get remove that
# code duplication.
from mod_pywebsocket.extensions import get_extension_processor
from mod_pywebsocket.handshake._base import get_mandatory_header
from mod_pywebsocket.handshake._base import HandshakeException
from mod_pywebsocket.handshake._base import parse_token_list
from mod_pywebsocket.handshake._base import validate_mandatory_header
from mod_pywebsocket.handshake._base import validate_subprotocol
from mod_pywebsocket.handshake._base import VersionException

And note that with WebDriver BiDi, we'll also want to have the ability to send some invalid messages, such as text messages that aren't valid UTF-8.

Has anyone looked into these libraries in detail? Is there a possible path where we can have just one library which is patchable enough for all of our needs?

cc @web-platform-tests/wpt-core-team + websockets/ folks @jdm @ricea @zqzhang

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions