mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2025-02-01 15:55:28 +00:00
Editor for request cookies
This commit is contained in:
parent
0f269f7423
commit
f33b483110
@ -1,14 +1,16 @@
|
|||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
import os, sys, copy
|
import os
|
||||||
|
import sys
|
||||||
import urwid
|
import urwid
|
||||||
from netlib import odict
|
from netlib import odict
|
||||||
from . import common, grideditor, contentview, signals, searchable, tabs
|
from . import common, grideditor, contentview, signals, searchable, tabs
|
||||||
from . import flowdetailview
|
from . import flowdetailview
|
||||||
from .. import utils, flow, controller
|
from .. import utils, controller
|
||||||
from ..protocol.http import HTTPRequest, HTTPResponse, CONTENT_MISSING, decoded
|
from ..protocol.http import HTTPRequest, HTTPResponse, CONTENT_MISSING, decoded
|
||||||
|
|
||||||
|
|
||||||
class SearchError(Exception): pass
|
class SearchError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def _mkhelp():
|
def _mkhelp():
|
||||||
@ -114,6 +116,7 @@ cache = utils.LRUCache(200)
|
|||||||
TAB_REQ = 0
|
TAB_REQ = 0
|
||||||
TAB_RESP = 1
|
TAB_RESP = 1
|
||||||
|
|
||||||
|
|
||||||
class FlowView(tabs.Tabs):
|
class FlowView(tabs.Tabs):
|
||||||
highlight_color = "focusfield"
|
highlight_color = "focusfield"
|
||||||
|
|
||||||
@ -201,13 +204,16 @@ class FlowView(tabs.Tabs):
|
|||||||
viewmode = self.viewmode_get()
|
viewmode = self.viewmode_get()
|
||||||
msg, body = self.content_view(viewmode, conn)
|
msg, body = self.content_view(viewmode, conn)
|
||||||
|
|
||||||
cols = [urwid.Text(
|
cols = [
|
||||||
|
urwid.Text(
|
||||||
[
|
[
|
||||||
("heading", msg),
|
("heading", msg),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
cols.append(urwid.Text([
|
cols.append(
|
||||||
|
urwid.Text(
|
||||||
|
[
|
||||||
" ",
|
" ",
|
||||||
('heading', "["),
|
('heading', "["),
|
||||||
('heading_key', "m"),
|
('heading_key', "m"),
|
||||||
@ -305,6 +311,11 @@ class FlowView(tabs.Tabs):
|
|||||||
if key == "y":
|
if key == "y":
|
||||||
self.edit_form(conn)
|
self.edit_form(conn)
|
||||||
|
|
||||||
|
def set_cookies(self, lst, conn):
|
||||||
|
od = odict.ODict(lst)
|
||||||
|
conn.set_cookies(od)
|
||||||
|
signals.flow_change.send(self, flow = self.flow)
|
||||||
|
|
||||||
def edit(self, part):
|
def edit(self, part):
|
||||||
if self.tab_offset == TAB_REQ:
|
if self.tab_offset == TAB_REQ:
|
||||||
message = self.flow.request
|
message = self.flow.request
|
||||||
@ -318,6 +329,16 @@ class FlowView(tabs.Tabs):
|
|||||||
message = self.flow.response
|
message = self.flow.response
|
||||||
|
|
||||||
self.flow.backup()
|
self.flow.backup()
|
||||||
|
if message == self.flow.request and part == "c":
|
||||||
|
self.master.view_grideditor(
|
||||||
|
grideditor.CookieEditor(
|
||||||
|
self.master,
|
||||||
|
message.get_cookies().lst,
|
||||||
|
self.set_cookies,
|
||||||
|
message
|
||||||
|
)
|
||||||
|
)
|
||||||
|
pass
|
||||||
if part == "r":
|
if part == "r":
|
||||||
with decoded(message):
|
with decoded(message):
|
||||||
# Fix an issue caused by some editors when editing a
|
# Fix an issue caused by some editors when editing a
|
||||||
@ -381,7 +402,7 @@ class FlowView(tabs.Tabs):
|
|||||||
keys = common.METHOD_OPTIONS,
|
keys = common.METHOD_OPTIONS,
|
||||||
callback = self.edit_method
|
callback = self.edit_method
|
||||||
)
|
)
|
||||||
elif part == "c":
|
elif part == "o":
|
||||||
signals.status_prompt.send(
|
signals.status_prompt.send(
|
||||||
prompt = "Code",
|
prompt = "Code",
|
||||||
text = str(message.code),
|
text = str(message.code),
|
||||||
@ -508,14 +529,19 @@ class FlowView(tabs.Tabs):
|
|||||||
elif conn:
|
elif conn:
|
||||||
if key == "b":
|
if key == "b":
|
||||||
if self.tab_offset == TAB_REQ:
|
if self.tab_offset == TAB_REQ:
|
||||||
common.ask_save_body("q", self.master, self.state, self.flow)
|
common.ask_save_body(
|
||||||
|
"q", self.master, self.state, self.flow
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
common.ask_save_body("s", self.master, self.state, self.flow)
|
common.ask_save_body(
|
||||||
|
"s", self.master, self.state, self.flow
|
||||||
|
)
|
||||||
elif key == "e":
|
elif key == "e":
|
||||||
if self.tab_offset == TAB_REQ:
|
if self.tab_offset == TAB_REQ:
|
||||||
signals.status_prompt_onekey.send(
|
signals.status_prompt_onekey.send(
|
||||||
prompt = "Edit request",
|
prompt = "Edit request",
|
||||||
keys = (
|
keys = (
|
||||||
|
("cookie", "c"),
|
||||||
("query", "q"),
|
("query", "q"),
|
||||||
("path", "p"),
|
("path", "p"),
|
||||||
("url", "u"),
|
("url", "u"),
|
||||||
@ -530,7 +556,7 @@ class FlowView(tabs.Tabs):
|
|||||||
signals.status_prompt_onekey.send(
|
signals.status_prompt_onekey.send(
|
||||||
prompt = "Edit response",
|
prompt = "Edit response",
|
||||||
keys = (
|
keys = (
|
||||||
("code", "c"),
|
("code", "o"),
|
||||||
("message", "m"),
|
("message", "m"),
|
||||||
("header", "h"),
|
("header", "h"),
|
||||||
("raw body", "r"),
|
("raw body", "r"),
|
||||||
|
@ -543,3 +543,9 @@ class HostPatternEditor(GridEditor):
|
|||||||
re.compile(val, re.IGNORECASE)
|
re.compile(val, re.IGNORECASE)
|
||||||
except re.error as e:
|
except re.error as e:
|
||||||
return "Invalid regex: %s" % str(e)
|
return "Invalid regex: %s" % str(e)
|
||||||
|
|
||||||
|
|
||||||
|
class CookieEditor(GridEditor):
|
||||||
|
title = "Editing request Cookie header"
|
||||||
|
columns = 2
|
||||||
|
headings = ("Name", "Value")
|
||||||
|
Loading…
Reference in New Issue
Block a user