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
|
Unreleased: mitmproxy next
|
||||||
==========================
|
==========================
|
||||||
|
|
||||||
|
* Fix query parameters in asgiapp addon (@jpstotz)
|
||||||
* --- TODO: add new PRs above this line ---
|
* --- TODO: add new PRs above this line ---
|
||||||
|
|
||||||
* ... and various other fixes, documentation improvements, dependency version bumps, etc.
|
* ... 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.
|
# (byte string) – URL portion after the ?, percent-encoded.
|
||||||
query_string: bytes
|
query_string: bytes
|
||||||
if len(quoted_path) > 1:
|
if len(quoted_path) > 1:
|
||||||
query_string = quoted_path[1].encode()
|
query_string = urllib.parse.unquote(quoted_path[1]).encode()
|
||||||
else:
|
else:
|
||||||
query_string = b""
|
query_string = b""
|
||||||
|
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
|
import json
|
||||||
|
|
||||||
import flask
|
import flask
|
||||||
|
from flask import request
|
||||||
|
|
||||||
from .. import tservers
|
from .. import tservers
|
||||||
from mitmproxy.addons import asgiapp
|
from mitmproxy.addons import asgiapp
|
||||||
@ -11,6 +14,14 @@ def hello():
|
|||||||
return "testapp"
|
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")
|
@tapp.route("/error")
|
||||||
def error():
|
def error():
|
||||||
raise ValueError("An exception...")
|
raise ValueError("An exception...")
|
||||||
@ -38,6 +49,12 @@ class TestApp(tservers.HTTPProxyTest):
|
|||||||
ret = p.request("get:'http://testapp/'")
|
ret = p.request("get:'http://testapp/'")
|
||||||
assert b"testapp" in ret.content
|
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):
|
def test_app_err(self):
|
||||||
p = self.pathoc()
|
p = self.pathoc()
|
||||||
with p.connect():
|
with p.connect():
|
||||||
@ -50,4 +67,4 @@ class TestApp(tservers.HTTPProxyTest):
|
|||||||
with p.connect():
|
with p.connect():
|
||||||
ret = p.request("get:'http://noresponseapp/'")
|
ret = p.request("get:'http://noresponseapp/'")
|
||||||
assert ret.status_code == 500
|
assert ret.status_code == 500
|
||||||
assert b"ASGI Error" in ret.content
|
assert b"ASGI Error" in ret.content
|
||||||
|
Loading…
Reference in New Issue
Block a user