Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -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)
------------------

Expand Down
14 changes: 11 additions & 3 deletions hyperframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -461,15 +464,20 @@ 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))
return data

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)
Expand Down