Merge pull request #4271 from jpstotz/asgi-query

asgiapp.py: fix query parameters
This commit is contained in:
Maximilian Hils 2020-11-07 09:48:56 +01:00 committed by GitHub
commit b45147e91d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 2 deletions

View File

@ -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.

View File

@ -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""

View File

@ -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&param2=2'")
assert b'{"param1": "1", "param2": "2"}' == ret.data.content
def test_app_err(self):
p = self.pathoc()
with p.connect():
@ -50,4 +67,4 @@ class TestApp(tservers.HTTPProxyTest):
with p.connect():
ret = p.request("get:'http://noresponseapp/'")
assert ret.status_code == 500
assert b"ASGI Error" in ret.content
assert b"ASGI Error" in ret.content