mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-29 02:57:19 +00:00
TLD and SLD are now highlighted using publicsuffix
- Added time.time() as the default for the start time on fake requests
This commit is contained in:
parent
df06c4da3b
commit
94ca23b782
@ -1,5 +1,6 @@
|
|||||||
import re
|
import re
|
||||||
import urllib
|
import urllib
|
||||||
|
import time
|
||||||
from typing import Optional, AnyStr, Dict, Iterable, Tuple, Union
|
from typing import Optional, AnyStr, Dict, Iterable, Tuple, Union
|
||||||
|
|
||||||
from mitmproxy.coretypes import multidict
|
from mitmproxy.coretypes import multidict
|
||||||
@ -101,6 +102,7 @@ class Request(message.Message):
|
|||||||
)
|
)
|
||||||
|
|
||||||
req.url = url
|
req.url = url
|
||||||
|
req.timestamp_start = time.time()
|
||||||
|
|
||||||
# Headers can be list or dict, we differentiate here.
|
# Headers can be list or dict, we differentiate here.
|
||||||
if isinstance(headers, dict):
|
if isinstance(headers, dict):
|
||||||
|
@ -4,6 +4,7 @@ import datetime
|
|||||||
import time
|
import time
|
||||||
import math
|
import math
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
|
from publicsuffix2 import get_sld, get_tld
|
||||||
|
|
||||||
import urwid
|
import urwid
|
||||||
import urwid.util
|
import urwid.util
|
||||||
@ -195,24 +196,29 @@ def rle_append_beginning_modify(rle, a_r):
|
|||||||
rle[0:0] = [(a, r)]
|
rle[0:0] = [(a, r)]
|
||||||
|
|
||||||
|
|
||||||
def colorize_host(s):
|
def colorize_host(host):
|
||||||
if len(s) == 0 or s[0] == '[' or s.split('.')[-1].isdigit():
|
tld = get_tld(host)
|
||||||
main_part = -1
|
sld = get_sld(host)
|
||||||
else:
|
|
||||||
main_part = 1 # TODO: second-level domains (https://publicsuffix.org/list/)
|
|
||||||
part = 0
|
|
||||||
attr = []
|
attr = []
|
||||||
for i in reversed(range(len(s))):
|
|
||||||
c = s[i]
|
tld_size = len(tld)
|
||||||
if c == '.':
|
sld_size = len(sld) - tld_size
|
||||||
part += 1
|
|
||||||
if c in ".:[]":
|
for letter in reversed(range(len(host))):
|
||||||
a = 'url_punctuation'
|
character = host[letter]
|
||||||
elif part == main_part:
|
if tld_size > 0:
|
||||||
a = 'url_domain'
|
style = 'url_domain'
|
||||||
|
tld_size -= 1
|
||||||
|
elif tld_size == 0:
|
||||||
|
style = 'text'
|
||||||
|
tld_size -= 1
|
||||||
|
elif sld_size > 0:
|
||||||
|
sld_size -= 1
|
||||||
|
style = 'url_extension'
|
||||||
else:
|
else:
|
||||||
a = 'text'
|
style = 'text'
|
||||||
rle_append_beginning_modify(attr, (a, len(c.encode())))
|
rle_append_beginning_modify(attr, (style, len(character.encode())))
|
||||||
return attr
|
return attr
|
||||||
|
|
||||||
|
|
||||||
@ -510,7 +516,7 @@ def format_flow(f, focus, extended=False, hostheader=False, cols=False, layout='
|
|||||||
d = dict(
|
d = dict(
|
||||||
focus=focus,
|
focus=focus,
|
||||||
extended=extended,
|
extended=extended,
|
||||||
two_line=extended or cols < 80,
|
two_line=extended or cols < 100,
|
||||||
cols=cols,
|
cols=cols,
|
||||||
intercepted=f.intercepted,
|
intercepted=f.intercepted,
|
||||||
acked=acked,
|
acked=acked,
|
||||||
|
1
setup.py
1
setup.py
@ -81,6 +81,7 @@ setup(
|
|||||||
"tornado>=4.3,<5.2",
|
"tornado>=4.3,<5.2",
|
||||||
"urwid>=2.0.1,<2.1",
|
"urwid>=2.0.1,<2.1",
|
||||||
"wsproto>=0.13.0,<0.14.0",
|
"wsproto>=0.13.0,<0.14.0",
|
||||||
|
"publicsuffix2~=2.20"
|
||||||
],
|
],
|
||||||
extras_require={
|
extras_require={
|
||||||
':sys_platform == "win32"': [
|
':sys_platform == "win32"': [
|
||||||
|
Loading…
Reference in New Issue
Block a user