Skip to content

Commit 8e176c2

Browse files
committed
Cast some data read from dump files to str, to prevent unicode promotion.
This fixes a bug that caused a traceback when de-serialized requests were replayed. Also adds unit tests for the problem.
1 parent 2a90ea6 commit 8e176c2

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

libmproxy/proxy.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,11 @@ def get_state(self):
198198
def from_state(klass, state):
199199
return klass(
200200
ClientConnect.from_state(state["client_conn"]),
201-
state["host"],
201+
str(state["host"]),
202202
state["port"],
203-
state["scheme"],
204-
state["method"],
205-
state["path"],
203+
str(state["scheme"]),
204+
str(state["method"]),
205+
str(state["path"]),
206206
utils.Headers.from_state(state["headers"]),
207207
base64.decodestring(state["content"]),
208208
state["timestamp"]
@@ -353,7 +353,7 @@ def from_state(klass, request, state):
353353
return klass(
354354
request,
355355
state["code"],
356-
state["msg"],
356+
str(state["msg"]),
357357
utils.Headers.from_state(state["headers"]),
358358
base64.decodestring(state["content"]),
359359
state["timestamp"],

test/test_flow.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -385,14 +385,18 @@ def _treader(self):
385385
def test_roundtrip(self):
386386
sio = StringIO()
387387
f = tutils.tflow()
388+
f.request.content = "".join(chr(i) for i in range(255))
388389
w = flow.FlowWriter(sio)
389390
w.add(f)
390391

391392
sio.seek(0)
392393
r = flow.FlowReader(sio)
393394
l = list(r.stream())
394395
assert len(l) == 1
395-
assert l[0] == f
396+
397+
f2 = l[0]
398+
assert f2 == f
399+
assert f2.request.assemble() == f.request.assemble()
396400

397401
def test_load_flows(self):
398402
r = self._treader()

0 commit comments

Comments
 (0)