mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
Merge pull request #4271 from jpstotz/asgi-query
asgiapp.py: fix query parameters
This commit is contained in:
commit
b45147e91d
@ -4,6 +4,7 @@ Release History
|
||||
Unreleased: mitmproxy next
|
||||
==========================
|
||||
|
||||
* Fix query parameters in asgiapp addon (@jpstotz)
|
||||
* --- TODO: add new PRs above this line ---
|
||||
|
||||
* ... and various other fixes, documentation improvements, dependency version bumps, etc.
|
||||
|
@ -55,7 +55,7 @@ def make_scope(flow: http.HTTPFlow) -> dict:
|
||||
# (byte string) – URL portion after the ?, percent-encoded.
|
||||
query_string: bytes
|
||||
if len(quoted_path) > 1:
|
||||
query_string = quoted_path[1].encode()
|
||||
query_string = urllib.parse.unquote(quoted_path[1]).encode()
|
||||
else:
|
||||
query_string = b""
|
||||
|
||||
|
@ -1,4 +1,7 @@
|
||||
import json
|
||||
|
||||
import flask
|
||||
from flask import request
|
||||
|
||||
from .. import tservers
|
||||
from mitmproxy.addons import asgiapp
|
||||
@ -11,6 +14,14 @@ def hello():
|
||||
return "testapp"
|
||||
|
||||
|
||||
@tapp.route("/parameters")
|
||||
def request_check():
|
||||
args = {}
|
||||
for k in request.args.keys():
|
||||
args[k] = request.args[k]
|
||||
return json.dumps(args)
|
||||
|
||||
|
||||
@tapp.route("/error")
|
||||
def error():
|
||||
raise ValueError("An exception...")
|
||||
@ -38,6 +49,12 @@ class TestApp(tservers.HTTPProxyTest):
|
||||
ret = p.request("get:'http://testapp/'")
|
||||
assert b"testapp" in ret.content
|
||||
|
||||
def test_parameters(self):
|
||||
p = self.pathoc()
|
||||
with p.connect():
|
||||
ret = p.request("get:'http://testapp/parameters?param1=1¶m2=2'")
|
||||
assert b'{"param1": "1", "param2": "2"}' == ret.data.content
|
||||
|
||||
def test_app_err(self):
|
||||
p = self.pathoc()
|
||||
with p.connect():
|
||||
|
Loading…
Reference in New Issue
Block a user