mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 08:11:00 +00:00
minor fixes
This commit is contained in:
parent
9f0889d541
commit
9b40e1072c
@ -6,6 +6,7 @@ import sys
|
|||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
import urwid
|
import urwid
|
||||||
|
from typing import Optional, Union # noqa
|
||||||
|
|
||||||
from mitmproxy import contentviews
|
from mitmproxy import contentviews
|
||||||
from mitmproxy import controller
|
from mitmproxy import controller
|
||||||
@ -105,7 +106,8 @@ footer = [
|
|||||||
class FlowViewHeader(urwid.WidgetWrap):
|
class FlowViewHeader(urwid.WidgetWrap):
|
||||||
|
|
||||||
def __init__(self, master, f):
|
def __init__(self, master, f):
|
||||||
self.master, self.flow = master, f
|
self.master = master # type: "mitmproxy.console.master.ConsoleMaster"
|
||||||
|
self.flow = f # type: models.HTTPFlow
|
||||||
self._w = common.format_flow(
|
self._w = common.format_flow(
|
||||||
f,
|
f,
|
||||||
False,
|
False,
|
||||||
@ -530,13 +532,6 @@ class FlowView(tabs.Tabs):
|
|||||||
)
|
)
|
||||||
signals.flow_change.send(self, flow = self.flow)
|
signals.flow_change.send(self, flow = self.flow)
|
||||||
|
|
||||||
def delete_body(self, t):
|
|
||||||
if self.tab_offset == TAB_REQ:
|
|
||||||
self.flow.request.content = None
|
|
||||||
else:
|
|
||||||
self.flow.response.content = None
|
|
||||||
signals.flow_change.send(self, flow = self.flow)
|
|
||||||
|
|
||||||
def keypress(self, size, key):
|
def keypress(self, size, key):
|
||||||
key = super(self.__class__, self).keypress(size, key)
|
key = super(self.__class__, self).keypress(size, key)
|
||||||
|
|
||||||
@ -545,6 +540,8 @@ class FlowView(tabs.Tabs):
|
|||||||
return
|
return
|
||||||
|
|
||||||
key = common.shortcuts(key)
|
key = common.shortcuts(key)
|
||||||
|
|
||||||
|
conn = None # type: Optional[Union[models.HTTPRequest, models.HTTPResponse]]
|
||||||
if self.tab_offset == TAB_REQ:
|
if self.tab_offset == TAB_REQ:
|
||||||
conn = self.flow.request
|
conn = self.flow.request
|
||||||
elif self.tab_offset == TAB_RESP:
|
elif self.tab_offset == TAB_RESP:
|
||||||
@ -691,15 +688,8 @@ class FlowView(tabs.Tabs):
|
|||||||
args = (scope, self.flow, common.copy_to_clipboard_or_prompt)
|
args = (scope, self.flow, common.copy_to_clipboard_or_prompt)
|
||||||
)
|
)
|
||||||
elif key == "x":
|
elif key == "x":
|
||||||
signals.status_prompt_onekey.send(
|
conn.content = None
|
||||||
prompt = "Delete body",
|
signals.flow_change.send(self, flow=self.flow)
|
||||||
keys = (
|
|
||||||
("completely", "c"),
|
|
||||||
("mark as missing", "m"),
|
|
||||||
),
|
|
||||||
callback = self.delete_body
|
|
||||||
)
|
|
||||||
key = None
|
|
||||||
elif key == "v":
|
elif key == "v":
|
||||||
if conn.raw_content:
|
if conn.raw_content:
|
||||||
t = conn.headers.get("content-type")
|
t = conn.headers.get("content-type")
|
||||||
@ -713,7 +703,9 @@ class FlowView(tabs.Tabs):
|
|||||||
self.flow.backup()
|
self.flow.backup()
|
||||||
e = conn.headers.get("content-encoding", "identity")
|
e = conn.headers.get("content-encoding", "identity")
|
||||||
if e != "identity":
|
if e != "identity":
|
||||||
if not conn.decode():
|
try:
|
||||||
|
conn.decode()
|
||||||
|
except ValueError:
|
||||||
signals.status_message.send(
|
signals.status_message.send(
|
||||||
message = "Could not decode - invalid data?"
|
message = "Could not decode - invalid data?"
|
||||||
)
|
)
|
||||||
|
@ -20,6 +20,8 @@ import logging
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from typing import Mapping # noqa
|
||||||
|
|
||||||
import html2text
|
import html2text
|
||||||
import lxml.etree
|
import lxml.etree
|
||||||
import lxml.html
|
import lxml.html
|
||||||
@ -76,6 +78,7 @@ def pretty_json(s):
|
|||||||
|
|
||||||
|
|
||||||
def format_dict(d):
|
def format_dict(d):
|
||||||
|
# type: (Mapping[Union[str,bytes], Union[str,bytes]]) -> Generator[Tuple[Union[str,bytes], Union[str,bytes]]]
|
||||||
"""
|
"""
|
||||||
Helper function that transforms the given dictionary into a list of
|
Helper function that transforms the given dictionary into a list of
|
||||||
("key", key )
|
("key", key )
|
||||||
@ -85,7 +88,7 @@ def format_dict(d):
|
|||||||
max_key_len = max(len(k) for k in d.keys())
|
max_key_len = max(len(k) for k in d.keys())
|
||||||
max_key_len = min(max_key_len, KEY_MAX)
|
max_key_len = min(max_key_len, KEY_MAX)
|
||||||
for key, value in d.items():
|
for key, value in d.items():
|
||||||
key += ":"
|
key += b":" if isinstance(key, bytes) else u":"
|
||||||
key = key.ljust(max_key_len + 2)
|
key = key.ljust(max_key_len + 2)
|
||||||
yield [
|
yield [
|
||||||
("header", key),
|
("header", key),
|
||||||
@ -278,6 +281,10 @@ class ViewURLEncoded(View):
|
|||||||
content_types = ["application/x-www-form-urlencoded"]
|
content_types = ["application/x-www-form-urlencoded"]
|
||||||
|
|
||||||
def __call__(self, data, **metadata):
|
def __call__(self, data, **metadata):
|
||||||
|
try:
|
||||||
|
data = data.decode("ascii","strict")
|
||||||
|
except ValueError:
|
||||||
|
return None
|
||||||
d = url.decode(data)
|
d = url.decode(data)
|
||||||
return "URLEncoded form", format_dict(multidict.MultiDict(d))
|
return "URLEncoded form", format_dict(multidict.MultiDict(d))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user