Add a pretty-printing mode for urlencoded form data.
This commit is contained in:
parent
76b4c6ba82
commit
94ae720a22
|
@ -924,6 +924,17 @@ class ConsoleMaster(flow.FlowMaster):
|
|||
break
|
||||
self._trailer(sum(len(i) for i in lines), txt)
|
||||
|
||||
def _view_conn_urlencoded(self, lines, txt):
|
||||
txt.append(urwid.Text(("highlight", "URLencoded data:\n")))
|
||||
txt.append(
|
||||
urwid.Text(
|
||||
format_keyvals(
|
||||
[(k+":", v) for (k, v) in lines],
|
||||
key = "header",
|
||||
val = "text"
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
def _find_pretty_view(self, content, hdrItems, txt):
|
||||
ctype = None
|
||||
|
@ -931,9 +942,13 @@ class ConsoleMaster(flow.FlowMaster):
|
|||
if i[0] == "content-type":
|
||||
ctype = i[1]
|
||||
break
|
||||
if ctype and "x-www-form-urlencoded" in ctype:
|
||||
data = utils.urldecode(content)
|
||||
if data:
|
||||
return self._view_conn_urlencoded(data, txt)
|
||||
if utils.isXML(content):
|
||||
return self._view_conn_xmlish(content, txt)
|
||||
if ctype and "application/json" in ctype:
|
||||
elif ctype and "application/json" in ctype:
|
||||
lines = utils.pretty_json(content)
|
||||
if lines:
|
||||
return self._view_conn_json(lines, txt)
|
||||
|
|
|
@ -12,7 +12,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
import re, os, subprocess, datetime, textwrap, errno, sys, time, functools, copy
|
||||
import re, os, subprocess, datetime, textwrap, errno
|
||||
import time, functools, copy, cgi
|
||||
import json
|
||||
|
||||
CERT_SLEEP_TIME = 1
|
||||
|
@ -120,6 +121,10 @@ def pretty_json(s):
|
|||
return json.dumps(p, sort_keys=True, indent=4).split("\n")
|
||||
|
||||
|
||||
def urldecode(s):
|
||||
return cgi.parse_qsl(s)
|
||||
|
||||
|
||||
def hexdump(s):
|
||||
"""
|
||||
Returns a set of typles:
|
||||
|
|
|
@ -221,6 +221,12 @@ class upretty_json(libpry.AutoTree):
|
|||
assert not utils.pretty_json("moo")
|
||||
|
||||
|
||||
class u_urldecode(libpry.AutoTree):
|
||||
def test_one(self):
|
||||
s = "one=two&three=four"
|
||||
assert len(utils.urldecode(s)) == 2
|
||||
|
||||
|
||||
class udummy_ca(libpry.AutoTree):
|
||||
def test_all(self):
|
||||
d = self.tmpdir()
|
||||
|
@ -306,6 +312,7 @@ tests = [
|
|||
uData(),
|
||||
upretty_xmlish(),
|
||||
upretty_json(),
|
||||
u_urldecode(),
|
||||
udummy_ca(),
|
||||
udummy_cert(),
|
||||
uLRUCache(),
|
||||
|
|
Loading…
Reference in New Issue