Repository navigation
Continue with the new API, add Rejection functionality - #93
Conversation
This makes the tests clearer, utilising pytest rather than unittest structures and taking the total lines down from around 800 to around 500. In addition it fixes a number of bugs found via these tests. This is a precurser for adding an API to allow for rejection of the initial request.
This allows for a SERVER-WSConnection to reject the websocket upgrade request with a custom response (including a body), it also allows for a CLIENT-WSConnection to emit events relating to a response that has rejected the upgrade request. The event API is written to short cut the most likely path in the server case, i.e. rejecting with a 400 code and no body. This is opposed to say copying the h11 event API.
Kriechi
left a comment
There was a problem hiding this comment.
In general this looks ok - a few minor comments.
| You also need to provide the application glue. To send a WebSocket message:: | ||
|
|
||
| ws.send_data("Hello world!") | ||
| ws.send(Data(data="Hello world!")) |
There was a problem hiding this comment.
Is specifying the data keyword arg really necessary? In the spirit of KISS, I would omit it in all examples and docs.
There was a problem hiding this comment.
One more comment: this creates a Data object, but the documentation states ... to send a WebSocket message .... Should we consider renaming it to plain, e.g., Message(data='foobar')?
There was a problem hiding this comment.
Reading a bit further, is this a mixup with the handshake "data"? Because there is now the RejectData event... which is badly named if I understand it correctly, that it applies only to the handshake?
There was a problem hiding this comment.
The data keyword is necessary, this is true for all init arguments for any Event subclass.
I'm happy with renaming Data to Message I think it matches the TextMessage and BytesMessage class naming.
I'm also open to a different name for the RejectData event, maybe RejectBody is clearer?
There was a problem hiding this comment.
Data is renamed Message in a commit I've just pushed.
This includes the event restructure and the introduction of the rejection mechanism. It should help users understand how to use wsproto.
This allows for more control over the acceptance response for servers and for the retrieval of this information for clients.
As suggested ``This command has been deprecated. Use `twine check` instead`` switch to twine to check the README format. See https://packaging.python.org/guides/making-a-pypi-friendly-readme/#validating-restructuredtext-markup
This makes it clearer what this event represents and also matches the naming of the TextMessage and BytesMessage events.
|
@Kriechi Could you take another look? |
|
Thanks |
This is a continuation of #85 to allow for a connection request to be rejected in server mode or in client mode for the rejection information to be emitted. In addition it adds the ability to customise the headers of the acceptance response (or again emits them).
The API is designed for what I think is the standard use case whereby a simple rejection is all that is required i.e. 400 with no body.