Skip to content

Commit

Permalink
🔧 Expand default text mimetypes mentioned in #1023
Browse files Browse the repository at this point in the history
♻️ define "DEFAULT_TEXT_MIMETYPES" and move to utilities.py
  • Loading branch information
monkut committed Aug 12, 2022
1 parent 0370119 commit 71c8aa3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 3 additions & 3 deletions zappa/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
# so handle both scenarios.
try:
from zappa.middleware import ZappaWSGIMiddleware
from zappa.utilities import merge_headers, parse_s3_url
from zappa.utilities import merge_headers, parse_s3_url, DEFAULT_TEXT_MIMETYPES
from zappa.wsgi import common_log, create_wsgi_request
except ImportError: # pragma: no cover
from .middleware import ZappaWSGIMiddleware
from .utilities import merge_headers, parse_s3_url
from .utilities import merge_headers, parse_s3_url, DEFAULT_TEXT_MIMETYPES
from .wsgi import common_log, create_wsgi_request


Expand Down Expand Up @@ -286,7 +286,7 @@ def _process_response_body(response: Response, settings: ModuleType) -> Tuple[st
"""
encode_body_as_base64 = False
if settings.BINARY_SUPPORT:
handle_as_text_mimetypes = ("text/", "application/json")
handle_as_text_mimetypes = DEFAULT_TEXT_MIMETYPES
additional_text_mimetypes = getattr(settings, "ADDITIONAL_TEXT_MIMETYPES", None)
if additional_text_mimetypes:
handle_as_text_mimetypes += tuple(additional_text_mimetypes)
Expand Down
13 changes: 13 additions & 0 deletions zappa/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@
# Settings / Packaging
##

# mimetypes starting with entries defined here are considered as TEXT when BINARTY_SUPPORT is True.
# - Additional TEXT mimetypes may be defined with the 'ADDITIONAL_TEXT_MIMETYPES' setting.
DEFAULT_TEXT_MIMETYPES = (
"text/",
"application/json", # RFC 4627
"application/javascript", # RFC 4329
"application/ecmascript", # RFC 4329
"application/xml", # RFC 3023
"application/xml-external-parsed-entity", # RFC 3023
"application/xml-dtd", # RFC 3023
"image/svg+xml", # RFC 3023
)


def copytree(src, dst, metadata=True, symlinks=False, ignore=None):
"""
Expand Down

0 comments on commit 71c8aa3

Please sign in to comment.