Skip to content

Commit

Permalink
Improve "Customizing" section further.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjerdonek committed Jul 10, 2017
1 parent fc12ddc commit 49e6e26
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,18 @@ Server
Customizing Request Handling
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

To selectively bypass the handshake and respond with HTTP status codes other
than the default, the
To set additional response headers or to selectively bypass the handshake,
you can subclass :class:`~websockets.server.WebSocketServerProtocol`,
override the
:meth:`~websockets.server.WebSocketServerProtocol.get_response_status`
method can be overridden to return a different :class:`~http.HTTPStatus`
member.
method, and pass the class to :func:`~websockets.server.serve()` using the
``klass`` keyword argument.

If :meth:`~websockets.server.WebSocketServerProtocol.get_response_status`
returns a status code other than the default of
``HTTPStatus.SWITCHING_PROTOCOLS``, the
:class:`~websockets.server.WebSocketServerProtocol` object will close the
connection immediately and respond with that status code.

For example, the request headers can be examined and the request
authenticated to decide whether to return ``HTTPStatus.UNAUTHORIZED`` or
Expand All @@ -64,13 +71,9 @@ within this method:
* ``raw_request_headers``
* ``request_headers``

If :meth:`~websockets.server.WebSocketServerProtocol.get_response_status`
returns a status code other than the default of
``HTTPStatus.SWITCHING_PROTOCOLS``, the
:class:`~websockets.server.WebSocketServerProtocol` object will close the
connection immediately and respond with that status code. The
``set_header(key, value)`` function, which is provided as an argument to the
method, can be used to set additional response headers.
The ``set_header(key, value)`` function, which is provided as an argument to
``get_response_status()``, can be used to set additional response headers,
regardless of whether the handshake is aborted.

Client
......
Expand Down

0 comments on commit 49e6e26

Please sign in to comment.