WebSocketBadStatusException for handshake error
This commit is contained in:
liris
2015-07-30 09:31:36 +09:00
parent 0dcebf652b
commit ec06e86588
3 changed files with 14 additions and 1 deletions

View File

@@ -11,6 +11,7 @@ ChangeLog
- fix string formatting in exception (#196) - fix string formatting in exception (#196)
- fix typo in README.rst (#197) - fix typo in README.rst (#197)
- introduce on_data callback to pass data type. (#198) - introduce on_data callback to pass data type. (#198)
- WebSocketBadStatusException for Handshake error (#199)
- 0.32.0 - 0.32.0

View File

@@ -31,18 +31,21 @@ class WebSocketException(Exception):
""" """
pass pass
class WebSocketProtocolException(WebSocketException): class WebSocketProtocolException(WebSocketException):
""" """
If the webscoket protocol is invalid, this exception will be raised. If the webscoket protocol is invalid, this exception will be raised.
""" """
pass pass
class WebSocketPayloadException(WebSocketException): class WebSocketPayloadException(WebSocketException):
""" """
If the webscoket payload is invalid, this exception will be raised. If the webscoket payload is invalid, this exception will be raised.
""" """
pass pass
class WebSocketConnectionClosedException(WebSocketException): class WebSocketConnectionClosedException(WebSocketException):
""" """
If remote host closed the connection or some network error happened, If remote host closed the connection or some network error happened,
@@ -50,12 +53,14 @@ class WebSocketConnectionClosedException(WebSocketException):
""" """
pass pass
class WebSocketTimeoutException(WebSocketException): class WebSocketTimeoutException(WebSocketException):
""" """
WebSocketTimeoutException will be raised at socket timeout during read/write data. WebSocketTimeoutException will be raised at socket timeout during read/write data.
""" """
pass pass
class WebSocketProxyException(WebSocketException): class WebSocketProxyException(WebSocketException):
""" """
WebSocketProxyException will be raised when proxy error occured. WebSocketProxyException will be raised when proxy error occured.
@@ -63,3 +68,10 @@ class WebSocketProxyException(WebSocketException):
pass pass
class WebSocketBadStatusException(WebSocketException):
"""
WebSocketBadStatusException will be raised when we get bad handshake status code.
"""
def __init__(self, message, status_code):
super(WebSocketBadStatusException, self).__init__(message % status_code)
self.status_code = status_code

View File

@@ -108,7 +108,7 @@ def _get_handshake_headers(resource, host, port, options):
def _get_resp_headers(sock, success_status=101): def _get_resp_headers(sock, success_status=101):
status, resp_headers = read_headers(sock) status, resp_headers = read_headers(sock)
if status != success_status: if status != success_status:
raise WebSocketException("Handshake status %d" % status) raise WebSocketBadStatusException("Handshake status %d", status)
return status, resp_headers return status, resp_headers
_HEADERS_TO_CHECK = { _HEADERS_TO_CHECK = {