Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BugFix Updated Deprecated Werkzeug Functions #248

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions serverless_wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
import json
import os
import sys
from urllib.parse import urlencode, unquote, unquote_plus

from werkzeug.datastructures import Headers, iter_multi_items, MultiDict
from werkzeug.wrappers import Response
from werkzeug.urls import url_encode, url_unquote, url_unquote_plus
from werkzeug.http import HTTP_STATUS_CODES

from werkzeug.wrappers import Response

# List of MIME types that should not be base64 encoded. MIME types within `text/*`
# are included by default.
Expand Down Expand Up @@ -91,10 +91,10 @@ def encode_query_string(event):
params = ""
if is_alb_event(event):
params = MultiDict(
(url_unquote_plus(k), url_unquote_plus(v))
(unquote_plus(k), unquote_plus(v))
for k, v in iter_multi_items(params)
)
return url_encode(params)
return urlencode(params)


def get_script_name(headers, request_context):
Expand Down Expand Up @@ -151,7 +151,7 @@ def generate_response(response, event):
if response.data:
mimetype = response.mimetype or "text/plain"
if (
mimetype.startswith("text/") or mimetype in TEXT_MIME_TYPES
mimetype.startswith("text/") or mimetype in TEXT_MIME_TYPES
) and not response.headers.get("Content-Encoding", ""):
returndict["body"] = response.get_data(as_text=True)
returndict["isBase64Encoded"] = False
Expand All @@ -178,10 +178,10 @@ def handle_request(app, event, context):
return {}

if (
event.get("version") is None
and event.get("isBase64Encoded") is None
and event.get("requestPath") is not None
and not is_alb_event(event)
event.get("version") is None
and event.get("isBase64Encoded") is None
and event.get("requestPath") is not None
and not is_alb_event(event)
):
return handle_lambda_integration(app, event, context)

Expand All @@ -208,15 +208,15 @@ def handle_payload_v1(app, event, context):
script_name = "/" + base_path

if path_info.startswith(script_name):
path_info = path_info[len(script_name) :]
path_info = path_info[len(script_name):]

body = event.get("body") or ""
body = get_body_bytes(event, body)

environ = {
"CONTENT_LENGTH": str(len(body)),
"CONTENT_TYPE": headers.get("Content-Type", ""),
"PATH_INFO": url_unquote(path_info),
"PATH_INFO": unquote(path_info),
"QUERY_STRING": encode_query_string(event),
"REMOTE_ADDR": event.get("requestContext", {})
.get("identity", {})
Expand Down Expand Up @@ -260,7 +260,7 @@ def handle_payload_v2(app, event, context):
script_name = "/" + base_path

if path_info.startswith(script_name):
path_info = path_info[len(script_name) :]
path_info = path_info[len(script_name):]

body = event.get("body", "")
body = get_body_bytes(event, body)
Expand All @@ -270,7 +270,7 @@ def handle_payload_v2(app, event, context):
environ = {
"CONTENT_LENGTH": str(len(body or "")),
"CONTENT_TYPE": headers.get("Content-Type", ""),
"PATH_INFO": url_unquote(path_info),
"PATH_INFO": unquote(path_info),
"QUERY_STRING": event.get("rawQueryString", ""),
"REMOTE_ADDR": event.get("requestContext", {})
.get("http", {})
Expand Down Expand Up @@ -324,8 +324,8 @@ def handle_lambda_integration(app, event, context):
environ = {
"CONTENT_LENGTH": str(len(body or "")),
"CONTENT_TYPE": headers.get("Content-Type", ""),
"PATH_INFO": url_unquote(path_info),
"QUERY_STRING": url_encode(event.get("query", {})),
"PATH_INFO": unquote(path_info),
"QUERY_STRING": urlencode(event.get("query", {})),
"REMOTE_ADDR": event.get("identity", {}).get("sourceIp", ""),
"REMOTE_USER": event.get("principalId", ""),
"REQUEST_METHOD": event.get("method", ""),
Expand Down
Loading