http2: change header_block_fragment handling
This commit is contained in:
parent
5cecbdc168
commit
40fa113116
|
@ -48,13 +48,21 @@ class Frame(object):
|
||||||
self.flags = flags
|
self.flags = flags
|
||||||
self.stream_id = stream_id
|
self.stream_id = stream_id
|
||||||
|
|
||||||
def _check_frame_size(self, length):
|
@classmethod
|
||||||
max_length = self.state.http2_settings[
|
def _check_frame_size(self, length, state):
|
||||||
SettingsFrame.SETTINGS.SETTINGS_MAX_FRAME_SIZE]
|
from . import HTTP2Protocol
|
||||||
if length > max_length:
|
|
||||||
|
if state:
|
||||||
|
settings = state.http2_settings
|
||||||
|
else:
|
||||||
|
settings = HTTP2Protocol.HTTP2_DEFAULT_SETTINGS
|
||||||
|
|
||||||
|
max_frame_size = settings[SettingsFrame.SETTINGS.SETTINGS_MAX_FRAME_SIZE]
|
||||||
|
|
||||||
|
if length > max_frame_size:
|
||||||
raise NotImplementedError(
|
raise NotImplementedError(
|
||||||
"Frame size exceeded: %d, but only %d allowed." % (
|
"Frame size exceeded: %d, but only %d allowed." % (
|
||||||
length, max_length))
|
length, max_frame_size))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_file(self, fp, state=None):
|
def from_file(self, fp, state=None):
|
||||||
|
@ -70,7 +78,7 @@ class Frame(object):
|
||||||
flags = fields[3]
|
flags = fields[3]
|
||||||
stream_id = fields[4]
|
stream_id = fields[4]
|
||||||
|
|
||||||
# TODO: check frame size if <= current SETTINGS_MAX_FRAME_SIZE
|
self._check_frame_size(length, state)
|
||||||
|
|
||||||
payload = fp.safe_read(length)
|
payload = fp.safe_read(length)
|
||||||
return FRAMES[fields[2]].from_bytes(
|
return FRAMES[fields[2]].from_bytes(
|
||||||
|
@ -80,26 +88,11 @@ class Frame(object):
|
||||||
stream_id,
|
stream_id,
|
||||||
payload)
|
payload)
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def from_bytes(self, data, state=None):
|
|
||||||
fields = struct.unpack("!HBBBL", data[:9])
|
|
||||||
length = (fields[0] << 8) + fields[1]
|
|
||||||
# type is already deducted from class
|
|
||||||
flags = fields[3]
|
|
||||||
stream_id = fields[4]
|
|
||||||
|
|
||||||
return FRAMES[fields[2]].from_bytes(
|
|
||||||
state,
|
|
||||||
length,
|
|
||||||
flags,
|
|
||||||
stream_id,
|
|
||||||
data[9:])
|
|
||||||
|
|
||||||
def to_bytes(self):
|
def to_bytes(self):
|
||||||
payload = self.payload_bytes()
|
payload = self.payload_bytes()
|
||||||
self.length = len(payload)
|
self.length = len(payload)
|
||||||
|
|
||||||
self._check_frame_size(self.length)
|
self._check_frame_size(self.length, self.state)
|
||||||
|
|
||||||
b = struct.pack('!HB', self.length & 0xFFFF00, self.length & 0x0000FF)
|
b = struct.pack('!HB', self.length & 0xFFFF00, self.length & 0x0000FF)
|
||||||
b += struct.pack('!B', self.TYPE)
|
b += struct.pack('!B', self.TYPE)
|
||||||
|
@ -192,17 +185,14 @@ class HeadersFrame(Frame):
|
||||||
length=0,
|
length=0,
|
||||||
flags=Frame.FLAG_NO_FLAGS,
|
flags=Frame.FLAG_NO_FLAGS,
|
||||||
stream_id=0x0,
|
stream_id=0x0,
|
||||||
headers=None,
|
header_block_fragment=b'',
|
||||||
pad_length=0,
|
pad_length=0,
|
||||||
exclusive=False,
|
exclusive=False,
|
||||||
stream_dependency=0x0,
|
stream_dependency=0x0,
|
||||||
weight=0):
|
weight=0):
|
||||||
super(HeadersFrame, self).__init__(state, length, flags, stream_id)
|
super(HeadersFrame, self).__init__(state, length, flags, stream_id)
|
||||||
|
|
||||||
if headers is None:
|
self.header_block_fragment = header_block_fragment
|
||||||
headers = []
|
|
||||||
|
|
||||||
self.headers = headers
|
|
||||||
self.pad_length = pad_length
|
self.pad_length = pad_length
|
||||||
self.exclusive = exclusive
|
self.exclusive = exclusive
|
||||||
self.stream_dependency = stream_dependency
|
self.stream_dependency = stream_dependency
|
||||||
|
@ -220,23 +210,14 @@ class HeadersFrame(Frame):
|
||||||
|
|
||||||
if f.flags & self.FLAG_PRIORITY:
|
if f.flags & self.FLAG_PRIORITY:
|
||||||
f.stream_dependency, f.weight = struct.unpack(
|
f.stream_dependency, f.weight = struct.unpack(
|
||||||
'!LB', header_block_fragment[:5])
|
'!LB', f.header_block_fragment[:5])
|
||||||
f.exclusive = bool(f.stream_dependency >> 31)
|
f.exclusive = bool(f.stream_dependency >> 31)
|
||||||
f.stream_dependency &= 0x7FFFFFFF
|
f.stream_dependency &= 0x7FFFFFFF
|
||||||
f.header_block_fragment = f.header_block_fragment[5:]
|
f.header_block_fragment = f.header_block_fragment[5:]
|
||||||
|
|
||||||
# TODO only do this if END_HEADERS or something...
|
|
||||||
# for header, value in f.state.decoder.decode(f.header_block_fragment):
|
|
||||||
# f.headers.append((header, value))
|
|
||||||
|
|
||||||
return f
|
return f
|
||||||
|
|
||||||
def payload_bytes(self):
|
def payload_bytes(self):
|
||||||
"""
|
|
||||||
This encodes all headers with HPACK
|
|
||||||
Do NOT call this method twice - it will change the encoder state!
|
|
||||||
"""
|
|
||||||
|
|
||||||
if self.stream_id == 0x0:
|
if self.stream_id == 0x0:
|
||||||
raise ValueError('HEADERS frames MUST be associated with a stream.')
|
raise ValueError('HEADERS frames MUST be associated with a stream.')
|
||||||
|
|
||||||
|
@ -249,9 +230,7 @@ class HeadersFrame(Frame):
|
||||||
(int(self.exclusive) << 31) | self.stream_dependency,
|
(int(self.exclusive) << 31) | self.stream_dependency,
|
||||||
self.weight)
|
self.weight)
|
||||||
|
|
||||||
# TODO: maybe remove that and only deal with header_block_fragments
|
b += self.header_block_fragment
|
||||||
# inside frames
|
|
||||||
b += self.state.encoder.encode(self.headers)
|
|
||||||
|
|
||||||
if self.flags & self.FLAG_PADDED:
|
if self.flags & self.FLAG_PADDED:
|
||||||
b += b'\0' * self.pad_length
|
b += b'\0' * self.pad_length
|
||||||
|
@ -269,11 +248,7 @@ class HeadersFrame(Frame):
|
||||||
if self.flags & self.FLAG_PADDED:
|
if self.flags & self.FLAG_PADDED:
|
||||||
s.append("padding: %d" % self.pad_length)
|
s.append("padding: %d" % self.pad_length)
|
||||||
|
|
||||||
if not self.headers:
|
s.append("header_block_fragment: %s" % self.header_block_fragment.encode('hex'))
|
||||||
s.append("headers: None")
|
|
||||||
else:
|
|
||||||
for header, value in self.headers:
|
|
||||||
s.append("%s: %s" % (header, value))
|
|
||||||
|
|
||||||
return "\n".join(s)
|
return "\n".join(s)
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,22 @@ import tutils
|
||||||
|
|
||||||
from nose.tools import assert_equal
|
from nose.tools import assert_equal
|
||||||
|
|
||||||
|
class FileAdapter(object):
|
||||||
|
def __init__(self, data, is_hex=True):
|
||||||
|
self.position = 0
|
||||||
|
if is_hex:
|
||||||
|
self.data = data.decode('hex')
|
||||||
|
else:
|
||||||
|
self.data = data
|
||||||
|
|
||||||
|
def safe_read(self, length):
|
||||||
|
if self.position + length > len(self.data):
|
||||||
|
raise ValueError("not enough bytes to read")
|
||||||
|
|
||||||
|
value = self.data[self.position:self.position + length]
|
||||||
|
self.position += length
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
def test_invalid_flags():
|
def test_invalid_flags():
|
||||||
tutils.raises(
|
tutils.raises(
|
||||||
|
@ -26,14 +42,6 @@ def test_frame_equality():
|
||||||
payload='foobar')
|
payload='foobar')
|
||||||
assert_equal(a, b)
|
assert_equal(a, b)
|
||||||
|
|
||||||
|
|
||||||
def test_too_large_frames():
|
|
||||||
DataFrame(
|
|
||||||
length=6,
|
|
||||||
flags=Frame.FLAG_END_STREAM,
|
|
||||||
stream_id=0x1234567)
|
|
||||||
|
|
||||||
|
|
||||||
def test_data_frame_to_bytes():
|
def test_data_frame_to_bytes():
|
||||||
f = DataFrame(
|
f = DataFrame(
|
||||||
length=6,
|
length=6,
|
||||||
|
@ -61,7 +69,7 @@ def test_data_frame_to_bytes():
|
||||||
|
|
||||||
|
|
||||||
def test_data_frame_from_bytes():
|
def test_data_frame_from_bytes():
|
||||||
f = Frame.from_bytes('000006000101234567666f6f626172'.decode('hex'))
|
f = Frame.from_file(FileAdapter('000006000101234567666f6f626172'))
|
||||||
assert isinstance(f, DataFrame)
|
assert isinstance(f, DataFrame)
|
||||||
assert_equal(f.length, 6)
|
assert_equal(f.length, 6)
|
||||||
assert_equal(f.TYPE, DataFrame.TYPE)
|
assert_equal(f.TYPE, DataFrame.TYPE)
|
||||||
|
@ -69,7 +77,7 @@ def test_data_frame_from_bytes():
|
||||||
assert_equal(f.stream_id, 0x1234567)
|
assert_equal(f.stream_id, 0x1234567)
|
||||||
assert_equal(f.payload, 'foobar')
|
assert_equal(f.payload, 'foobar')
|
||||||
|
|
||||||
f = Frame.from_bytes('00000a00090123456703666f6f626172000000'.decode('hex'))
|
f = Frame.from_file(FileAdapter('00000a00090123456703666f6f626172000000'))
|
||||||
assert isinstance(f, DataFrame)
|
assert isinstance(f, DataFrame)
|
||||||
assert_equal(f.length, 10)
|
assert_equal(f.length, 10)
|
||||||
assert_equal(f.TYPE, DataFrame.TYPE)
|
assert_equal(f.TYPE, DataFrame.TYPE)
|
||||||
|
@ -93,14 +101,14 @@ def test_headers_frame_to_bytes():
|
||||||
length=6,
|
length=6,
|
||||||
flags=(Frame.FLAG_NO_FLAGS),
|
flags=(Frame.FLAG_NO_FLAGS),
|
||||||
stream_id=0x1234567,
|
stream_id=0x1234567,
|
||||||
headers=[('host', 'foo.bar')])
|
header_block_fragment='668594e75e31d9'.decode('hex'))
|
||||||
assert_equal(f.to_bytes().encode('hex'), '000007010001234567668594e75e31d9')
|
assert_equal(f.to_bytes().encode('hex'), '000007010001234567668594e75e31d9')
|
||||||
|
|
||||||
f = HeadersFrame(
|
f = HeadersFrame(
|
||||||
length=10,
|
length=10,
|
||||||
flags=(HeadersFrame.FLAG_PADDED),
|
flags=(HeadersFrame.FLAG_PADDED),
|
||||||
stream_id=0x1234567,
|
stream_id=0x1234567,
|
||||||
headers=[('host', 'foo.bar')],
|
header_block_fragment='668594e75e31d9'.decode('hex'),
|
||||||
pad_length=3)
|
pad_length=3)
|
||||||
assert_equal(
|
assert_equal(
|
||||||
f.to_bytes().encode('hex'),
|
f.to_bytes().encode('hex'),
|
||||||
|
@ -110,7 +118,7 @@ def test_headers_frame_to_bytes():
|
||||||
length=10,
|
length=10,
|
||||||
flags=(HeadersFrame.FLAG_PRIORITY),
|
flags=(HeadersFrame.FLAG_PRIORITY),
|
||||||
stream_id=0x1234567,
|
stream_id=0x1234567,
|
||||||
headers=[('host', 'foo.bar')],
|
header_block_fragment='668594e75e31d9'.decode('hex'),
|
||||||
exclusive=True,
|
exclusive=True,
|
||||||
stream_dependency=0x7654321,
|
stream_dependency=0x7654321,
|
||||||
weight=42)
|
weight=42)
|
||||||
|
@ -122,7 +130,7 @@ def test_headers_frame_to_bytes():
|
||||||
length=14,
|
length=14,
|
||||||
flags=(HeadersFrame.FLAG_PADDED | HeadersFrame.FLAG_PRIORITY),
|
flags=(HeadersFrame.FLAG_PADDED | HeadersFrame.FLAG_PRIORITY),
|
||||||
stream_id=0x1234567,
|
stream_id=0x1234567,
|
||||||
headers=[('host', 'foo.bar')],
|
header_block_fragment='668594e75e31d9'.decode('hex'),
|
||||||
pad_length=3,
|
pad_length=3,
|
||||||
exclusive=True,
|
exclusive=True,
|
||||||
stream_dependency=0x7654321,
|
stream_dependency=0x7654321,
|
||||||
|
@ -135,7 +143,7 @@ def test_headers_frame_to_bytes():
|
||||||
length=14,
|
length=14,
|
||||||
flags=(HeadersFrame.FLAG_PADDED | HeadersFrame.FLAG_PRIORITY),
|
flags=(HeadersFrame.FLAG_PADDED | HeadersFrame.FLAG_PRIORITY),
|
||||||
stream_id=0x1234567,
|
stream_id=0x1234567,
|
||||||
headers=[('host', 'foo.bar')],
|
header_block_fragment='668594e75e31d9'.decode('hex'),
|
||||||
pad_length=3,
|
pad_length=3,
|
||||||
exclusive=False,
|
exclusive=False,
|
||||||
stream_dependency=0x7654321,
|
stream_dependency=0x7654321,
|
||||||
|
@ -148,60 +156,61 @@ def test_headers_frame_to_bytes():
|
||||||
length=6,
|
length=6,
|
||||||
flags=Frame.FLAG_NO_FLAGS,
|
flags=Frame.FLAG_NO_FLAGS,
|
||||||
stream_id=0x0,
|
stream_id=0x0,
|
||||||
headers=[('host', 'foo.bar')])
|
header_block_fragment='668594e75e31d9'.decode('hex'))
|
||||||
tutils.raises(ValueError, f.to_bytes)
|
tutils.raises(ValueError, f.to_bytes)
|
||||||
|
|
||||||
|
|
||||||
def test_headers_frame_from_bytes():
|
def test_headers_frame_from_bytes():
|
||||||
f = Frame.from_bytes('000007010001234567668594e75e31d9'.decode('hex'))
|
f = Frame.from_file(FileAdapter(
|
||||||
|
'000007010001234567668594e75e31d9'))
|
||||||
assert isinstance(f, HeadersFrame)
|
assert isinstance(f, HeadersFrame)
|
||||||
assert_equal(f.length, 7)
|
assert_equal(f.length, 7)
|
||||||
assert_equal(f.TYPE, HeadersFrame.TYPE)
|
assert_equal(f.TYPE, HeadersFrame.TYPE)
|
||||||
assert_equal(f.flags, Frame.FLAG_NO_FLAGS)
|
assert_equal(f.flags, Frame.FLAG_NO_FLAGS)
|
||||||
assert_equal(f.stream_id, 0x1234567)
|
assert_equal(f.stream_id, 0x1234567)
|
||||||
assert_equal(f.headers, [('host', 'foo.bar')])
|
assert_equal(f.header_block_fragment, '668594e75e31d9'.decode('hex'))
|
||||||
|
|
||||||
f = Frame.from_bytes(
|
f = Frame.from_file(FileAdapter(
|
||||||
'00000b01080123456703668594e75e31d9000000'.decode('hex'))
|
'00000b01080123456703668594e75e31d9000000'))
|
||||||
assert isinstance(f, HeadersFrame)
|
assert isinstance(f, HeadersFrame)
|
||||||
assert_equal(f.length, 11)
|
assert_equal(f.length, 11)
|
||||||
assert_equal(f.TYPE, HeadersFrame.TYPE)
|
assert_equal(f.TYPE, HeadersFrame.TYPE)
|
||||||
assert_equal(f.flags, HeadersFrame.FLAG_PADDED)
|
assert_equal(f.flags, HeadersFrame.FLAG_PADDED)
|
||||||
assert_equal(f.stream_id, 0x1234567)
|
assert_equal(f.stream_id, 0x1234567)
|
||||||
assert_equal(f.headers, [('host', 'foo.bar')])
|
assert_equal(f.header_block_fragment, '668594e75e31d9'.decode('hex'))
|
||||||
|
|
||||||
f = Frame.from_bytes(
|
f = Frame.from_file(FileAdapter(
|
||||||
'00000c012001234567876543212a668594e75e31d9'.decode('hex'))
|
'00000c012001234567876543212a668594e75e31d9'))
|
||||||
assert isinstance(f, HeadersFrame)
|
assert isinstance(f, HeadersFrame)
|
||||||
assert_equal(f.length, 12)
|
assert_equal(f.length, 12)
|
||||||
assert_equal(f.TYPE, HeadersFrame.TYPE)
|
assert_equal(f.TYPE, HeadersFrame.TYPE)
|
||||||
assert_equal(f.flags, HeadersFrame.FLAG_PRIORITY)
|
assert_equal(f.flags, HeadersFrame.FLAG_PRIORITY)
|
||||||
assert_equal(f.stream_id, 0x1234567)
|
assert_equal(f.stream_id, 0x1234567)
|
||||||
assert_equal(f.headers, [('host', 'foo.bar')])
|
assert_equal(f.header_block_fragment, '668594e75e31d9'.decode('hex'))
|
||||||
assert_equal(f.exclusive, True)
|
assert_equal(f.exclusive, True)
|
||||||
assert_equal(f.stream_dependency, 0x7654321)
|
assert_equal(f.stream_dependency, 0x7654321)
|
||||||
assert_equal(f.weight, 42)
|
assert_equal(f.weight, 42)
|
||||||
|
|
||||||
f = Frame.from_bytes(
|
f = Frame.from_file(FileAdapter(
|
||||||
'00001001280123456703876543212a668594e75e31d9000000'.decode('hex'))
|
'00001001280123456703876543212a668594e75e31d9000000'))
|
||||||
assert isinstance(f, HeadersFrame)
|
assert isinstance(f, HeadersFrame)
|
||||||
assert_equal(f.length, 16)
|
assert_equal(f.length, 16)
|
||||||
assert_equal(f.TYPE, HeadersFrame.TYPE)
|
assert_equal(f.TYPE, HeadersFrame.TYPE)
|
||||||
assert_equal(f.flags, HeadersFrame.FLAG_PADDED | HeadersFrame.FLAG_PRIORITY)
|
assert_equal(f.flags, HeadersFrame.FLAG_PADDED | HeadersFrame.FLAG_PRIORITY)
|
||||||
assert_equal(f.stream_id, 0x1234567)
|
assert_equal(f.stream_id, 0x1234567)
|
||||||
assert_equal(f.headers, [('host', 'foo.bar')])
|
assert_equal(f.header_block_fragment, '668594e75e31d9'.decode('hex'))
|
||||||
assert_equal(f.exclusive, True)
|
assert_equal(f.exclusive, True)
|
||||||
assert_equal(f.stream_dependency, 0x7654321)
|
assert_equal(f.stream_dependency, 0x7654321)
|
||||||
assert_equal(f.weight, 42)
|
assert_equal(f.weight, 42)
|
||||||
|
|
||||||
f = Frame.from_bytes(
|
f = Frame.from_file(FileAdapter(
|
||||||
'00001001280123456703076543212a668594e75e31d9000000'.decode('hex'))
|
'00001001280123456703076543212a668594e75e31d9000000'))
|
||||||
assert isinstance(f, HeadersFrame)
|
assert isinstance(f, HeadersFrame)
|
||||||
assert_equal(f.length, 16)
|
assert_equal(f.length, 16)
|
||||||
assert_equal(f.TYPE, HeadersFrame.TYPE)
|
assert_equal(f.TYPE, HeadersFrame.TYPE)
|
||||||
assert_equal(f.flags, HeadersFrame.FLAG_PADDED | HeadersFrame.FLAG_PRIORITY)
|
assert_equal(f.flags, HeadersFrame.FLAG_PADDED | HeadersFrame.FLAG_PRIORITY)
|
||||||
assert_equal(f.stream_id, 0x1234567)
|
assert_equal(f.stream_id, 0x1234567)
|
||||||
assert_equal(f.headers, [('host', 'foo.bar')])
|
assert_equal(f.header_block_fragment, '668594e75e31d9'.decode('hex'))
|
||||||
assert_equal(f.exclusive, False)
|
assert_equal(f.exclusive, False)
|
||||||
assert_equal(f.stream_dependency, 0x7654321)
|
assert_equal(f.stream_dependency, 0x7654321)
|
||||||
assert_equal(f.weight, 42)
|
assert_equal(f.weight, 42)
|
||||||
|
@ -212,7 +221,7 @@ def test_headers_frame_human_readable():
|
||||||
length=7,
|
length=7,
|
||||||
flags=(HeadersFrame.FLAG_PADDED | HeadersFrame.FLAG_PRIORITY),
|
flags=(HeadersFrame.FLAG_PADDED | HeadersFrame.FLAG_PRIORITY),
|
||||||
stream_id=0x1234567,
|
stream_id=0x1234567,
|
||||||
headers=[],
|
header_block_fragment=b'',
|
||||||
pad_length=3,
|
pad_length=3,
|
||||||
exclusive=False,
|
exclusive=False,
|
||||||
stream_dependency=0x7654321,
|
stream_dependency=0x7654321,
|
||||||
|
@ -223,7 +232,7 @@ def test_headers_frame_human_readable():
|
||||||
length=14,
|
length=14,
|
||||||
flags=(HeadersFrame.FLAG_PADDED | HeadersFrame.FLAG_PRIORITY),
|
flags=(HeadersFrame.FLAG_PADDED | HeadersFrame.FLAG_PRIORITY),
|
||||||
stream_id=0x1234567,
|
stream_id=0x1234567,
|
||||||
headers=[('host', 'foo.bar')],
|
header_block_fragment='668594e75e31d9'.decode('hex'),
|
||||||
pad_length=3,
|
pad_length=3,
|
||||||
exclusive=False,
|
exclusive=False,
|
||||||
stream_dependency=0x7654321,
|
stream_dependency=0x7654321,
|
||||||
|
@ -266,7 +275,7 @@ def test_priority_frame_to_bytes():
|
||||||
|
|
||||||
|
|
||||||
def test_priority_frame_from_bytes():
|
def test_priority_frame_from_bytes():
|
||||||
f = Frame.from_bytes('000005020001234567876543212a'.decode('hex'))
|
f = Frame.from_file(FileAdapter('000005020001234567876543212a'))
|
||||||
assert isinstance(f, PriorityFrame)
|
assert isinstance(f, PriorityFrame)
|
||||||
assert_equal(f.length, 5)
|
assert_equal(f.length, 5)
|
||||||
assert_equal(f.TYPE, PriorityFrame.TYPE)
|
assert_equal(f.TYPE, PriorityFrame.TYPE)
|
||||||
|
@ -276,7 +285,7 @@ def test_priority_frame_from_bytes():
|
||||||
assert_equal(f.stream_dependency, 0x7654321)
|
assert_equal(f.stream_dependency, 0x7654321)
|
||||||
assert_equal(f.weight, 42)
|
assert_equal(f.weight, 42)
|
||||||
|
|
||||||
f = Frame.from_bytes('0000050200012345670765432115'.decode('hex'))
|
f = Frame.from_file(FileAdapter('0000050200012345670765432115'))
|
||||||
assert isinstance(f, PriorityFrame)
|
assert isinstance(f, PriorityFrame)
|
||||||
assert_equal(f.length, 5)
|
assert_equal(f.length, 5)
|
||||||
assert_equal(f.TYPE, PriorityFrame.TYPE)
|
assert_equal(f.TYPE, PriorityFrame.TYPE)
|
||||||
|
@ -314,7 +323,7 @@ def test_rst_stream_frame_to_bytes():
|
||||||
|
|
||||||
|
|
||||||
def test_rst_stream_frame_from_bytes():
|
def test_rst_stream_frame_from_bytes():
|
||||||
f = Frame.from_bytes('00000403000123456707654321'.decode('hex'))
|
f = Frame.from_file(FileAdapter('00000403000123456707654321'))
|
||||||
assert isinstance(f, RstStreamFrame)
|
assert isinstance(f, RstStreamFrame)
|
||||||
assert_equal(f.length, 4)
|
assert_equal(f.length, 4)
|
||||||
assert_equal(f.TYPE, RstStreamFrame.TYPE)
|
assert_equal(f.TYPE, RstStreamFrame.TYPE)
|
||||||
|
@ -372,21 +381,21 @@ def test_settings_frame_to_bytes():
|
||||||
|
|
||||||
|
|
||||||
def test_settings_frame_from_bytes():
|
def test_settings_frame_from_bytes():
|
||||||
f = Frame.from_bytes('000000040000000000'.decode('hex'))
|
f = Frame.from_file(FileAdapter('000000040000000000'))
|
||||||
assert isinstance(f, SettingsFrame)
|
assert isinstance(f, SettingsFrame)
|
||||||
assert_equal(f.length, 0)
|
assert_equal(f.length, 0)
|
||||||
assert_equal(f.TYPE, SettingsFrame.TYPE)
|
assert_equal(f.TYPE, SettingsFrame.TYPE)
|
||||||
assert_equal(f.flags, Frame.FLAG_NO_FLAGS)
|
assert_equal(f.flags, Frame.FLAG_NO_FLAGS)
|
||||||
assert_equal(f.stream_id, 0x0)
|
assert_equal(f.stream_id, 0x0)
|
||||||
|
|
||||||
f = Frame.from_bytes('000000040100000000'.decode('hex'))
|
f = Frame.from_file(FileAdapter('000000040100000000'))
|
||||||
assert isinstance(f, SettingsFrame)
|
assert isinstance(f, SettingsFrame)
|
||||||
assert_equal(f.length, 0)
|
assert_equal(f.length, 0)
|
||||||
assert_equal(f.TYPE, SettingsFrame.TYPE)
|
assert_equal(f.TYPE, SettingsFrame.TYPE)
|
||||||
assert_equal(f.flags, SettingsFrame.FLAG_ACK)
|
assert_equal(f.flags, SettingsFrame.FLAG_ACK)
|
||||||
assert_equal(f.stream_id, 0x0)
|
assert_equal(f.stream_id, 0x0)
|
||||||
|
|
||||||
f = Frame.from_bytes('000006040100000000000200000001'.decode('hex'))
|
f = Frame.from_file(FileAdapter('000006040100000000000200000001'))
|
||||||
assert isinstance(f, SettingsFrame)
|
assert isinstance(f, SettingsFrame)
|
||||||
assert_equal(f.length, 6)
|
assert_equal(f.length, 6)
|
||||||
assert_equal(f.TYPE, SettingsFrame.TYPE)
|
assert_equal(f.TYPE, SettingsFrame.TYPE)
|
||||||
|
@ -395,8 +404,8 @@ def test_settings_frame_from_bytes():
|
||||||
assert_equal(len(f.settings), 1)
|
assert_equal(len(f.settings), 1)
|
||||||
assert_equal(f.settings[SettingsFrame.SETTINGS.SETTINGS_ENABLE_PUSH], 1)
|
assert_equal(f.settings[SettingsFrame.SETTINGS.SETTINGS_ENABLE_PUSH], 1)
|
||||||
|
|
||||||
f = Frame.from_bytes(
|
f = Frame.from_file(FileAdapter(
|
||||||
'00000c040000000000000200000001000312345678'.decode('hex'))
|
'00000c040000000000000200000001000312345678'))
|
||||||
assert isinstance(f, SettingsFrame)
|
assert isinstance(f, SettingsFrame)
|
||||||
assert_equal(f.length, 12)
|
assert_equal(f.length, 12)
|
||||||
assert_equal(f.TYPE, SettingsFrame.TYPE)
|
assert_equal(f.TYPE, SettingsFrame.TYPE)
|
||||||
|
@ -466,7 +475,7 @@ def test_push_promise_frame_to_bytes():
|
||||||
|
|
||||||
|
|
||||||
def test_push_promise_frame_from_bytes():
|
def test_push_promise_frame_from_bytes():
|
||||||
f = Frame.from_bytes('00000a05000123456707654321666f6f626172'.decode('hex'))
|
f = Frame.from_file(FileAdapter('00000a05000123456707654321666f6f626172'))
|
||||||
assert isinstance(f, PushPromiseFrame)
|
assert isinstance(f, PushPromiseFrame)
|
||||||
assert_equal(f.length, 10)
|
assert_equal(f.length, 10)
|
||||||
assert_equal(f.TYPE, PushPromiseFrame.TYPE)
|
assert_equal(f.TYPE, PushPromiseFrame.TYPE)
|
||||||
|
@ -474,8 +483,8 @@ def test_push_promise_frame_from_bytes():
|
||||||
assert_equal(f.stream_id, 0x1234567)
|
assert_equal(f.stream_id, 0x1234567)
|
||||||
assert_equal(f.header_block_fragment, 'foobar')
|
assert_equal(f.header_block_fragment, 'foobar')
|
||||||
|
|
||||||
f = Frame.from_bytes(
|
f = Frame.from_file(FileAdapter(
|
||||||
'00000e0508012345670307654321666f6f626172000000'.decode('hex'))
|
'00000e0508012345670307654321666f6f626172000000'))
|
||||||
assert isinstance(f, PushPromiseFrame)
|
assert isinstance(f, PushPromiseFrame)
|
||||||
assert_equal(f.length, 14)
|
assert_equal(f.length, 14)
|
||||||
assert_equal(f.TYPE, PushPromiseFrame.TYPE)
|
assert_equal(f.TYPE, PushPromiseFrame.TYPE)
|
||||||
|
@ -522,7 +531,7 @@ def test_ping_frame_to_bytes():
|
||||||
|
|
||||||
|
|
||||||
def test_ping_frame_from_bytes():
|
def test_ping_frame_from_bytes():
|
||||||
f = Frame.from_bytes('000008060100000000666f6f6261720000'.decode('hex'))
|
f = Frame.from_file(FileAdapter('000008060100000000666f6f6261720000'))
|
||||||
assert isinstance(f, PingFrame)
|
assert isinstance(f, PingFrame)
|
||||||
assert_equal(f.length, 8)
|
assert_equal(f.length, 8)
|
||||||
assert_equal(f.TYPE, PingFrame.TYPE)
|
assert_equal(f.TYPE, PingFrame.TYPE)
|
||||||
|
@ -530,7 +539,7 @@ def test_ping_frame_from_bytes():
|
||||||
assert_equal(f.stream_id, 0x0)
|
assert_equal(f.stream_id, 0x0)
|
||||||
assert_equal(f.payload, b'foobar\0\0')
|
assert_equal(f.payload, b'foobar\0\0')
|
||||||
|
|
||||||
f = Frame.from_bytes('000008060000000000666f6f6261726465'.decode('hex'))
|
f = Frame.from_file(FileAdapter('000008060000000000666f6f6261726465'))
|
||||||
assert isinstance(f, PingFrame)
|
assert isinstance(f, PingFrame)
|
||||||
assert_equal(f.length, 8)
|
assert_equal(f.length, 8)
|
||||||
assert_equal(f.TYPE, PingFrame.TYPE)
|
assert_equal(f.TYPE, PingFrame.TYPE)
|
||||||
|
@ -581,8 +590,8 @@ def test_goaway_frame_to_bytes():
|
||||||
|
|
||||||
|
|
||||||
def test_goaway_frame_from_bytes():
|
def test_goaway_frame_from_bytes():
|
||||||
f = Frame.from_bytes(
|
f = Frame.from_file(FileAdapter(
|
||||||
'0000080700000000000123456787654321'.decode('hex'))
|
'0000080700000000000123456787654321'))
|
||||||
assert isinstance(f, GoAwayFrame)
|
assert isinstance(f, GoAwayFrame)
|
||||||
assert_equal(f.length, 8)
|
assert_equal(f.length, 8)
|
||||||
assert_equal(f.TYPE, GoAwayFrame.TYPE)
|
assert_equal(f.TYPE, GoAwayFrame.TYPE)
|
||||||
|
@ -592,8 +601,8 @@ def test_goaway_frame_from_bytes():
|
||||||
assert_equal(f.error_code, 0x87654321)
|
assert_equal(f.error_code, 0x87654321)
|
||||||
assert_equal(f.data, b'')
|
assert_equal(f.data, b'')
|
||||||
|
|
||||||
f = Frame.from_bytes(
|
f = Frame.from_file(FileAdapter(
|
||||||
'00000e0700000000000123456787654321666f6f626172'.decode('hex'))
|
'00000e0700000000000123456787654321666f6f626172'))
|
||||||
assert isinstance(f, GoAwayFrame)
|
assert isinstance(f, GoAwayFrame)
|
||||||
assert_equal(f.length, 14)
|
assert_equal(f.length, 14)
|
||||||
assert_equal(f.TYPE, GoAwayFrame.TYPE)
|
assert_equal(f.TYPE, GoAwayFrame.TYPE)
|
||||||
|
@ -642,7 +651,7 @@ def test_window_update_frame_to_bytes():
|
||||||
|
|
||||||
|
|
||||||
def test_window_update_frame_from_bytes():
|
def test_window_update_frame_from_bytes():
|
||||||
f = Frame.from_bytes('00000408000000000001234567'.decode('hex'))
|
f = Frame.from_file(FileAdapter('00000408000000000001234567'))
|
||||||
assert isinstance(f, WindowUpdateFrame)
|
assert isinstance(f, WindowUpdateFrame)
|
||||||
assert_equal(f.length, 4)
|
assert_equal(f.length, 4)
|
||||||
assert_equal(f.TYPE, WindowUpdateFrame.TYPE)
|
assert_equal(f.TYPE, WindowUpdateFrame.TYPE)
|
||||||
|
@ -677,7 +686,7 @@ def test_continuation_frame_to_bytes():
|
||||||
|
|
||||||
|
|
||||||
def test_continuation_frame_from_bytes():
|
def test_continuation_frame_from_bytes():
|
||||||
f = Frame.from_bytes('000006090401234567666f6f626172'.decode('hex'))
|
f = Frame.from_file(FileAdapter('000006090401234567666f6f626172'))
|
||||||
assert isinstance(f, ContinuationFrame)
|
assert isinstance(f, ContinuationFrame)
|
||||||
assert_equal(f.length, 6)
|
assert_equal(f.length, 6)
|
||||||
assert_equal(f.TYPE, ContinuationFrame.TYPE)
|
assert_equal(f.TYPE, ContinuationFrame.TYPE)
|
||||||
|
|
Loading…
Reference in New Issue