mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-27 02:24:18 +00:00
websockets: raw body specification
This commit is contained in:
parent
bddf81edfc
commit
d80fbc2410
@ -8,8 +8,8 @@ from . import base, generators, actions, message
|
|||||||
wf:c15:r'foo'
|
wf:c15:r'foo'
|
||||||
wf:fin:rsv1:rsv2:rsv3:mask
|
wf:fin:rsv1:rsv2:rsv3:mask
|
||||||
wf:-fin:-rsv1:-rsv2:-rsv3:-mask
|
wf:-fin:-rsv1:-rsv2:-rsv3:-mask
|
||||||
|
|
||||||
wf:l234
|
wf:l234
|
||||||
|
|
||||||
wf:mask:r"foo
|
wf:mask:r"foo
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -35,6 +35,11 @@ class Body(base.Value):
|
|||||||
preamble = "b"
|
preamble = "b"
|
||||||
|
|
||||||
|
|
||||||
|
class RawBody(base.Value):
|
||||||
|
unique_name = "Body"
|
||||||
|
preamble = "r"
|
||||||
|
|
||||||
|
|
||||||
class Fin(base.Boolean):
|
class Fin(base.Boolean):
|
||||||
name = "fin"
|
name = "fin"
|
||||||
|
|
||||||
@ -66,14 +71,16 @@ class KeyNone(base.CaselessLiteral):
|
|||||||
|
|
||||||
|
|
||||||
class Length(base.Integer):
|
class Length(base.Integer):
|
||||||
bounds = (0, 1<<64)
|
bounds = (0, 1 << 64)
|
||||||
preamble = "l"
|
preamble = "l"
|
||||||
|
|
||||||
|
|
||||||
|
class Times(base.Integer):
|
||||||
|
preamble = "x"
|
||||||
|
|
||||||
|
|
||||||
class WebsocketFrame(message.Message):
|
class WebsocketFrame(message.Message):
|
||||||
comps = (
|
comps = (
|
||||||
Body,
|
|
||||||
|
|
||||||
OpCode,
|
OpCode,
|
||||||
Length,
|
Length,
|
||||||
# Bit flags
|
# Bit flags
|
||||||
@ -87,6 +94,10 @@ class WebsocketFrame(message.Message):
|
|||||||
actions.InjectAt,
|
actions.InjectAt,
|
||||||
KeyNone,
|
KeyNone,
|
||||||
Key,
|
Key,
|
||||||
|
Times,
|
||||||
|
|
||||||
|
Body,
|
||||||
|
RawBody,
|
||||||
)
|
)
|
||||||
logattrs = ["body"]
|
logattrs = ["body"]
|
||||||
@property
|
@property
|
||||||
@ -97,6 +108,10 @@ class WebsocketFrame(message.Message):
|
|||||||
def body(self):
|
def body(self):
|
||||||
return self.tok(Body)
|
return self.tok(Body)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def rawbody(self):
|
||||||
|
return self.tok(RawBody)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def opcode(self):
|
def opcode(self):
|
||||||
return self.tok(OpCode)
|
return self.tok(OpCode)
|
||||||
@ -165,6 +180,9 @@ class WebsocketFrame(message.Message):
|
|||||||
if self.body:
|
if self.body:
|
||||||
bodygen = self.body.value.get_generator(settings)
|
bodygen = self.body.value.get_generator(settings)
|
||||||
length = len(self.body.value.get_generator(settings))
|
length = len(self.body.value.get_generator(settings))
|
||||||
|
elif self.rawbody:
|
||||||
|
bodygen = self.rawbody.value.get_generator(settings)
|
||||||
|
length = len(self.rawbody.value.get_generator(settings))
|
||||||
else:
|
else:
|
||||||
bodygen = None
|
bodygen = None
|
||||||
length = 0
|
length = 0
|
||||||
@ -187,7 +205,7 @@ class WebsocketFrame(message.Message):
|
|||||||
frame = netlib.websockets.FrameHeader(**frameparts)
|
frame = netlib.websockets.FrameHeader(**frameparts)
|
||||||
vals = [frame.to_bytes()]
|
vals = [frame.to_bytes()]
|
||||||
if bodygen:
|
if bodygen:
|
||||||
if frame.masking_key:
|
if frame.masking_key and not self.rawbody:
|
||||||
masker = netlib.websockets.Masker(frame.masking_key)
|
masker = netlib.websockets.Masker(frame.masking_key)
|
||||||
vals.append(
|
vals.append(
|
||||||
generators.TransformGenerator(
|
generators.TransformGenerator(
|
||||||
|
@ -76,6 +76,14 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td> r<a href="#valuespec">VALUE</a> </td>
|
||||||
|
<td>
|
||||||
|
Set the raw frame payload. This diesables masking, even if the
|
||||||
|
key is present.
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td> [-]rsv1 </td>
|
<td> [-]rsv1 </td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -15,6 +15,7 @@ class TestWebsocketFrame:
|
|||||||
"wf",
|
"wf",
|
||||||
"wf:dr",
|
"wf:dr",
|
||||||
"wf:b'foo'",
|
"wf:b'foo'",
|
||||||
|
"wf:mask:r'foo'",
|
||||||
"wf:l1024:b'foo'",
|
"wf:l1024:b'foo'",
|
||||||
"wf:cbinary",
|
"wf:cbinary",
|
||||||
"wf:c1",
|
"wf:c1",
|
||||||
@ -68,6 +69,13 @@ class TestWebsocketFrame:
|
|||||||
assert self.fr("wf:ctext").header.opcode ==\
|
assert self.fr("wf:ctext").header.opcode ==\
|
||||||
netlib.websockets.OPCODE.TEXT
|
netlib.websockets.OPCODE.TEXT
|
||||||
|
|
||||||
|
def test_rawbody(self):
|
||||||
|
frm = self.fr("wf:mask:r'foo'")
|
||||||
|
assert len(frm.payload) == 3
|
||||||
|
assert frm.payload != "foo"
|
||||||
|
|
||||||
|
assert self.fr("wf:r'foo'").payload == "foo"
|
||||||
|
|
||||||
def test_construction(self):
|
def test_construction(self):
|
||||||
# Simple server frame
|
# Simple server frame
|
||||||
frm = self.fr("wf:b'foo'")
|
frm = self.fr("wf:b'foo'")
|
||||||
|
Loading…
Reference in New Issue
Block a user