mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-22 07:08:10 +00:00
contentviews: ignore empty data
This commit is contained in:
parent
f8b4c7bd44
commit
a7f27259a7
@ -58,7 +58,7 @@ class ViewCSS(base.View):
|
||||
return "CSS", base.format_text(beautified)
|
||||
|
||||
def render_priority(self, data: bytes, *, content_type: Optional[str] = None, **metadata) -> float:
|
||||
return float(content_type == "text/css")
|
||||
return float(bool(data) and content_type == "text/css")
|
||||
|
||||
|
||||
if __name__ == "__main__": # pragma: no cover
|
||||
|
@ -45,7 +45,7 @@ class ViewGraphQL(base.View):
|
||||
return "GraphQL", base.format_text(format_query_list(data))
|
||||
|
||||
def render_priority(self, data: bytes, *, content_type: typing.Optional[str] = None, **metadata) -> float:
|
||||
if content_type != "application/json":
|
||||
if content_type != "application/json" or not data:
|
||||
return 0
|
||||
|
||||
data = parse_json(data)
|
||||
|
@ -59,4 +59,4 @@ class ViewJavaScript(base.View):
|
||||
return "JavaScript", base.format_text(res)
|
||||
|
||||
def render_priority(self, data: bytes, *, content_type: Optional[str] = None, **metadata) -> float:
|
||||
return float(content_type in self.__content_types)
|
||||
return float(bool(data) and content_type in self.__content_types)
|
||||
|
@ -47,6 +47,8 @@ class ViewJSON(base.View):
|
||||
return "JSON", format_json(data)
|
||||
|
||||
def render_priority(self, data: bytes, *, content_type: typing.Optional[str] = None, **metadata) -> float:
|
||||
if not data:
|
||||
return 0
|
||||
if content_type in (
|
||||
"application/json",
|
||||
"application/json-rpc",
|
||||
|
@ -50,4 +50,4 @@ class ViewMsgPack(base.View):
|
||||
return "MsgPack", format_msgpack(data)
|
||||
|
||||
def render_priority(self, data: bytes, *, content_type: typing.Optional[str] = None, **metadata) -> float:
|
||||
return float(content_type in self.__content_types)
|
||||
return float(bool(data) and content_type in self.__content_types)
|
||||
|
@ -21,4 +21,4 @@ class ViewMultipart(base.View):
|
||||
return "Multipart form", self._format(v)
|
||||
|
||||
def render_priority(self, data: bytes, *, content_type: Optional[str] = None, **metadata) -> float:
|
||||
return float(content_type == "multipart/form-data")
|
||||
return float(bool(data) and content_type == "multipart/form-data")
|
||||
|
@ -80,4 +80,4 @@ class ViewProtobuf(base.View):
|
||||
return "Protobuf", base.format_text(decoded)
|
||||
|
||||
def render_priority(self, data: bytes, *, content_type: Optional[str] = None, **metadata) -> float:
|
||||
return float(content_type in self.__content_types)
|
||||
return float(bool(data) and content_type in self.__content_types)
|
||||
|
@ -16,4 +16,4 @@ class ViewURLEncoded(base.View):
|
||||
return "URLEncoded form", base.format_pairs(d)
|
||||
|
||||
def render_priority(self, data: bytes, *, content_type: Optional[str] = None, **metadata) -> float:
|
||||
return float(content_type == "application/x-www-form-urlencoded")
|
||||
return float(bool(data) and content_type == "application/x-www-form-urlencoded")
|
||||
|
@ -21,4 +21,4 @@ class ViewWBXML(base.View):
|
||||
return None
|
||||
|
||||
def render_priority(self, data: bytes, *, content_type: Optional[str] = None, **metadata) -> float:
|
||||
return float(content_type in self.__content_types)
|
||||
return float(bool(data) and content_type in self.__content_types)
|
||||
|
@ -235,8 +235,10 @@ class ViewXmlHtml(base.View):
|
||||
return t, pretty
|
||||
|
||||
def render_priority(self, data: bytes, *, content_type: Optional[str] = None, **metadata) -> float:
|
||||
if not data:
|
||||
return 0
|
||||
if content_type in self.__content_types:
|
||||
return 1
|
||||
elif strutils.is_xml(data):
|
||||
return 0.4
|
||||
return float(content_type in self.__content_types)
|
||||
return 0
|
||||
|
Loading…
Reference in New Issue
Block a user