|
17 | 17 | import json
|
18 | 18 | import os
|
19 | 19 | import sys
|
| 20 | +from urllib.parse import unquote, unquote_plus, urlencode |
20 | 21 |
|
21 | 22 | from werkzeug.datastructures import Headers, MultiDict, iter_multi_items
|
22 | 23 | from werkzeug.http import HTTP_STATUS_CODES
|
23 |
| -from werkzeug.urls import url_encode, url_unquote, url_unquote_plus |
24 | 24 | from werkzeug.wrappers import Response
|
25 | 25 |
|
26 | 26 | # List of MIME types that should not be base64 encoded. MIME types within `text/*`
|
@@ -95,8 +95,8 @@ def encode_query_string(event):
|
95 | 95 | if not params:
|
96 | 96 | params = ""
|
97 | 97 | if is_alb_event(event):
|
98 |
| - params = MultiDict((url_unquote_plus(k), url_unquote_plus(v)) for k, v in iter_multi_items(params)) |
99 |
| - return url_encode(params) |
| 98 | + params = MultiDict((unquote_plus(k), unquote_plus(v)) for k, v in iter_multi_items(params)) |
| 99 | + return urlencode(params) |
100 | 100 |
|
101 | 101 |
|
102 | 102 | def get_script_name(headers, request_context):
|
@@ -203,7 +203,7 @@ def handle_payload_v1(app, event, context):
|
203 | 203 | environ = {
|
204 | 204 | "CONTENT_LENGTH": str(len(body)),
|
205 | 205 | "CONTENT_TYPE": headers.get("Content-Type", ""),
|
206 |
| - "PATH_INFO": url_unquote(path_info), |
| 206 | + "PATH_INFO": unquote(path_info), |
207 | 207 | "QUERY_STRING": encode_query_string(event),
|
208 | 208 | "REMOTE_ADDR": event.get("requestContext", {}).get("identity", {}).get("sourceIp", ""),
|
209 | 209 | "REMOTE_USER": event.get("requestContext", {}).get("authorizer", {}).get("principalId", ""),
|
@@ -247,7 +247,7 @@ def handle_payload_v2(app, event, context):
|
247 | 247 | environ = {
|
248 | 248 | "CONTENT_LENGTH": str(len(body)),
|
249 | 249 | "CONTENT_TYPE": headers.get("Content-Type", ""),
|
250 |
| - "PATH_INFO": url_unquote(path_info), |
| 250 | + "PATH_INFO": unquote(path_info), |
251 | 251 | "QUERY_STRING": event.get("rawQueryString", ""),
|
252 | 252 | "REMOTE_ADDR": event.get("requestContext", {}).get("http", {}).get("sourceIp", ""),
|
253 | 253 | "REMOTE_USER": event.get("requestContext", {}).get("authorizer", {}).get("principalId", ""),
|
@@ -295,8 +295,8 @@ def handle_lambda_integration(app, event, context):
|
295 | 295 | environ = {
|
296 | 296 | "CONTENT_LENGTH": str(len(body)),
|
297 | 297 | "CONTENT_TYPE": headers.get("Content-Type", ""),
|
298 |
| - "PATH_INFO": url_unquote(path_info), |
299 |
| - "QUERY_STRING": url_encode(event.get("query", {})), |
| 298 | + "PATH_INFO": unquote(path_info), |
| 299 | + "QUERY_STRING": urlencode(event.get("query", {})), |
300 | 300 | "REMOTE_ADDR": event.get("identity", {}).get("sourceIp", ""),
|
301 | 301 | "REMOTE_USER": event.get("principalId", ""),
|
302 | 302 | "REQUEST_METHOD": event.get("method", ""),
|
|
0 commit comments