Skip to content

Continue with the new API, add Rejection functionality - #93

Merged
pgjones merged 6 commits into
python-hyper:masterfrom
pgjones:master
Jan 4, 2019
Merged

pgjones merged 6 commits into
python-hyper:masterfrom
pgjones:master

Conversation

@pgjones

@pgjones pgjones commented Dec 30, 2018

Copy link
Copy Markdown
Member

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.

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 Kriechi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general this looks ok - a few minor comments.

Comment thread docs/source/basic-usage.rst Resolved
Comment thread docs/source/basic-usage.rst Resolved
Comment thread docs/source/basic-usage.rst Resolved
Comment thread docs/source/basic-usage.rst Outdated
You also need to provide the application glue. To send a WebSocket message::

ws.send_data("Hello world!")
ws.send(Data(data="Hello world!"))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is specifying the data keyword arg really necessary? In the spirit of KISS, I would omit it in all examples and docs.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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')?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
This makes it clearer what this event represents and also matches the
naming of the TextMessage and BytesMessage events.
@pgjones

pgjones commented Jan 3, 2019

Copy link
Copy Markdown
Member Author

@Kriechi Could you take another look?

@pgjones
pgjones merged commit c490762 into python-hyper:master Jan 4, 2019
@pgjones

pgjones commented Jan 4, 2019

Copy link
Copy Markdown
Member Author

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants