mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 08:11:00 +00:00
extracted server_copy_response to common
This commit is contained in:
parent
0a2d2d9390
commit
b77cd1af60
@ -3,7 +3,10 @@ import urwid
|
|||||||
import urwid.util
|
import urwid.util
|
||||||
from .. import utils
|
from .. import utils
|
||||||
from ..protocol.http import CONTENT_MISSING
|
from ..protocol.http import CONTENT_MISSING
|
||||||
|
try:
|
||||||
|
import pyperclip
|
||||||
|
except:
|
||||||
|
pyperclip = False
|
||||||
|
|
||||||
VIEW_LIST = 0
|
VIEW_LIST = 0
|
||||||
VIEW_FLOW = 1
|
VIEW_FLOW = 1
|
||||||
@ -161,6 +164,21 @@ def raw_format_flow(f, focus, extended, padding):
|
|||||||
pile.append(urwid.Columns(resp, dividechars=1))
|
pile.append(urwid.Columns(resp, dividechars=1))
|
||||||
return urwid.Pile(pile)
|
return urwid.Pile(pile)
|
||||||
|
|
||||||
|
def server_copy_response( k, response, statusbar):
|
||||||
|
if pyperclip:
|
||||||
|
if k == "c":
|
||||||
|
try:
|
||||||
|
pyperclip.copy(response.get_decoded_content())
|
||||||
|
except TypeError:
|
||||||
|
statusbar.message("Content is binary or can be converted to text")
|
||||||
|
elif k == "h":
|
||||||
|
try:
|
||||||
|
pyperclip.copy(str(response.headers))
|
||||||
|
except TypeError:
|
||||||
|
statusbar.message("Error converting headers to text")
|
||||||
|
else:
|
||||||
|
statusbar.message("No clipboard support on your system, sorry.")
|
||||||
|
|
||||||
|
|
||||||
class FlowCache:
|
class FlowCache:
|
||||||
@utils.LRUCache(200)
|
@utils.LRUCache(200)
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
import urwid
|
import urwid
|
||||||
from . import common
|
from . import common
|
||||||
try:
|
|
||||||
import pyperclip
|
|
||||||
except:
|
|
||||||
pyperclip = False
|
|
||||||
|
|
||||||
def _mkhelp():
|
def _mkhelp():
|
||||||
text = []
|
text = []
|
||||||
@ -141,20 +137,6 @@ class ConnectionItem(common.WWrap):
|
|||||||
self.state.last_saveload,
|
self.state.last_saveload,
|
||||||
self.master.server_playback_path
|
self.master.server_playback_path
|
||||||
)
|
)
|
||||||
def server_copy_response(self, k):
|
|
||||||
if pyperclip:
|
|
||||||
if k == "c":
|
|
||||||
try:
|
|
||||||
pyperclip.copy(self.flow.response.get_decoded_content())
|
|
||||||
except TypeError:
|
|
||||||
self.master.statusbar.message("Content is binary or can be converted to text")
|
|
||||||
elif k == "h":
|
|
||||||
try:
|
|
||||||
pyperclip.copy(str(self.flow.response.headers))
|
|
||||||
except TypeError:
|
|
||||||
self.master.statusbar.message("Error converting headers to text")
|
|
||||||
else:
|
|
||||||
self.master.statusbar.message("No clipboard support on your system, sorry.")
|
|
||||||
|
|
||||||
def keypress(self, (maxcol,), key):
|
def keypress(self, (maxcol,), key):
|
||||||
key = common.shortcuts(key)
|
key = common.shortcuts(key)
|
||||||
@ -228,7 +210,9 @@ class ConnectionItem(common.WWrap):
|
|||||||
("content", "c"),
|
("content", "c"),
|
||||||
("headers", "h"),
|
("headers", "h"),
|
||||||
),
|
),
|
||||||
self.server_copy_response,
|
common.server_copy_response,
|
||||||
|
self.flow.response,
|
||||||
|
self.master.statusbar
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
return key
|
return key
|
||||||
|
@ -4,10 +4,7 @@ import urwid
|
|||||||
from . import common, grideditor, contentview
|
from . import common, grideditor, contentview
|
||||||
from .. import utils, flow, controller
|
from .. import utils, flow, controller
|
||||||
from ..protocol.http import HTTPResponse, CONTENT_MISSING, decoded
|
from ..protocol.http import HTTPResponse, CONTENT_MISSING, decoded
|
||||||
try:
|
|
||||||
import pyperclip
|
|
||||||
except:
|
|
||||||
pyperclip = False
|
|
||||||
|
|
||||||
class SearchError(Exception): pass
|
class SearchError(Exception): pass
|
||||||
|
|
||||||
@ -652,21 +649,6 @@ class FlowView(common.WWrap):
|
|||||||
)
|
)
|
||||||
self.master.refresh_flow(self.flow)
|
self.master.refresh_flow(self.flow)
|
||||||
|
|
||||||
def server_copy_response(self, k):
|
|
||||||
if pyperclip:
|
|
||||||
if k == "c":
|
|
||||||
try:
|
|
||||||
pyperclip.copy(self.flow.response.get_decoded_content())
|
|
||||||
except TypeError:
|
|
||||||
self.master.statusbar.message("Content is binary or can be converted to text")
|
|
||||||
elif k == "h":
|
|
||||||
try:
|
|
||||||
pyperclip.copy(str(self.flow.response.headers))
|
|
||||||
except TypeError:
|
|
||||||
self.master.statusbar.message("Error converting headers to text")
|
|
||||||
else:
|
|
||||||
self.master.statusbar.message("No clipboard support on your system, sorry.")
|
|
||||||
|
|
||||||
def delete_body(self, t):
|
def delete_body(self, t):
|
||||||
if t == "m":
|
if t == "m":
|
||||||
val = CONTENT_MISSING
|
val = CONTENT_MISSING
|
||||||
@ -777,7 +759,9 @@ class FlowView(common.WWrap):
|
|||||||
("content", "c"),
|
("content", "c"),
|
||||||
("headers", "h"),
|
("headers", "h"),
|
||||||
),
|
),
|
||||||
self.server_copy_response,
|
common.server_copy_response,
|
||||||
|
self.flow.response,
|
||||||
|
self.master.statusbar
|
||||||
)
|
)
|
||||||
elif key == "m":
|
elif key == "m":
|
||||||
p = list(contentview.view_prompts)
|
p = list(contentview.view_prompts)
|
||||||
|
Loading…
Reference in New Issue
Block a user