From 06c4ebf4d1dd5d92bdf86c50573dbee9df327522 Mon Sep 17 00:00:00 2001 From: Cory Benfield Date: Mon, 1 Feb 2016 12:25:58 +0000 Subject: [PATCH 1/2] Throw InvalidFrameError more often. --- hyperframe/frame.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/hyperframe/frame.py b/hyperframe/frame.py index 00c2b97..1c54d18 100644 --- a/hyperframe/frame.py +++ b/hyperframe/frame.py @@ -310,7 +310,10 @@ def serialize_body(self): def parse_body(self, data): if len(data) != 4: - raise ValueError() + raise InvalidFrameError( + "RST_STREAM must have 4 byte body: actual length %s." % + len(data) + ) try: self.error_code = struct.unpack("!L", data)[0] @@ -461,7 +464,10 @@ def __init__(self, stream_id=0, opaque_data=b'', **kwargs): def serialize_body(self): if len(self.opaque_data) > 8: - raise ValueError() + raise InvalidFrameError( + "PING frame may not have more than 8 bytes of data, got %s" % + self.opaque_data + ) data = self.opaque_data data += b'\x00' * (8 - len(self.opaque_data)) @@ -469,7 +475,9 @@ def serialize_body(self): def parse_body(self, data): if len(data) != 8: - raise ValueError() + raise InvalidFrameError( + "PING frame must have 8 byte length: got %s" % len(data) + ) self.opaque_data = data.tobytes() self.body_len = len(data) From f25ec36862f05fa307354ab4de8ca11a9c84a0ef Mon Sep 17 00:00:00 2001 From: Cory Benfield Date: Mon, 1 Feb 2016 12:26:07 +0000 Subject: [PATCH 2/2] Changelog for #33. --- HISTORY.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/HISTORY.rst b/HISTORY.rst index 5393968..7695a20 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,6 +1,16 @@ Release History =============== +dev +--- + +**API Changes (Backward-compatible)** + +- Invalid PING frame bodies now raise ``InvalidFrameError``, not + ``ValueError``. Note that ``InvalidFrameError`` is a ``ValueError`` subclass. +- Invalid RST_STREAM frame bodies now raise ``InvalidFramError``, not + ``ValueError``. Note that ``InvalidFrameError`` is a ``ValueError`` subclass. + 3.1.1 (2016-01-18) ------------------