-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#908) Update BINARY_SUPPORT to use Content-Encoding to identify if d…
…ata is binary (#1155) * 🔧 migrate #971 to lastest master * 🎨 run black/isort * ♻️ refactor to allow for other binary ignore types based on mimetype. (currently openapi schema can't be passed as text. * 🎨 run black/fix flake8 * 🔧 add EXCEPTION_HANDLER setting * 🐛 fix zappa_returndict["body"] assignment * 📝 add temp debug info * 🔥 delete unnecessary print statements * ♻️ Update comments and minor refactor for clarity * ♻️ refactor for ease of testing and clarity * 🎨 fix flake8 * ✨ add `additional_text_mimetypes` setting ✅ add testcases for additional_text_mimetypes handling * 🔧 Expand default text mimetypes mentioned in #1023 ♻️ define "DEFAULT_TEXT_MIMETYPES" and move to utilities.py * 🎨 run black/isort * 🎨 run black/isort * 🎨 remove unnecesasry comment (black now reformats code) 🎨 change commented lines to docstring for test app
- Loading branch information
Showing
12 changed files
with
397 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"nobinarysupport": { | ||
"s3_bucket": "lmbda", | ||
"app_function": "tests.test_app.hello_world", | ||
"delete_local_zip": true, | ||
"binary_support": false, | ||
"additional_text_mimetypes": ["application/custommimetype"] | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
tests/test_binary_support_additional_text_mimetypes_settings.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
API_STAGE = "dev" | ||
APP_FUNCTION = "app" | ||
APP_MODULE = "tests.test_wsgi_binary_support_app" | ||
BINARY_SUPPORT = True | ||
CONTEXT_HEADER_MAPPINGS = {} | ||
DEBUG = "True" | ||
DJANGO_SETTINGS = None | ||
DOMAIN = "api.example.com" | ||
ENVIRONMENT_VARIABLES = {} | ||
LOG_LEVEL = "DEBUG" | ||
PROJECT_NAME = "binary_support_settings" | ||
COGNITO_TRIGGER_MAPPING = {} | ||
EXCEPTION_HANDLER = None | ||
ADDITIONAL_TEXT_MIMETYPES = ["application/vnd.oai.openapi"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
API_STAGE = "dev" | ||
APP_FUNCTION = "app" | ||
APP_MODULE = "tests.test_wsgi_binary_support_app" | ||
BINARY_SUPPORT = True | ||
CONTEXT_HEADER_MAPPINGS = {} | ||
DEBUG = "True" | ||
DJANGO_SETTINGS = None | ||
DOMAIN = "api.example.com" | ||
ENVIRONMENT_VARIABLES = {} | ||
LOG_LEVEL = "DEBUG" | ||
PROJECT_NAME = "binary_support_settings" | ||
COGNITO_TRIGGER_MAPPING = {} | ||
EXCEPTION_HANDLER = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
""" | ||
This test application exists to confirm how Zappa handles WSGI application | ||
_responses_ when Binary Support is enabled. | ||
""" | ||
|
||
import gzip | ||
import json | ||
|
||
from flask import Flask, Response | ||
|
||
app = Flask(__name__) | ||
|
||
|
||
@app.route("/textplain_mimetype_response1", methods=["GET"]) | ||
def text_mimetype_response_1(): | ||
return Response(response="OK", mimetype="text/plain") | ||
|
||
|
||
@app.route("/textarbitrary_mimetype_response1", methods=["GET"]) | ||
def text_mimetype_response_2(): | ||
return Response(response="OK", mimetype="text/arbitary") | ||
|
||
|
||
@app.route("/json_mimetype_response1", methods=["GET"]) | ||
def json_mimetype_response_1(): | ||
return Response(response=json.dumps({"some": "data"}), mimetype="application/json") | ||
|
||
|
||
@app.route("/arbitrarybinary_mimetype_response1", methods=["GET"]) | ||
def arbitrary_mimetype_response_1(): | ||
return Response(response=b"some binary data", mimetype="arbitrary/binary_mimetype") | ||
|
||
|
||
@app.route("/arbitrarybinary_mimetype_response2", methods=["GET"]) | ||
def arbitrary_mimetype_response_3(): | ||
return Response(response="doesnt_matter", mimetype="definitely_not_text") | ||
|
||
|
||
@app.route("/content_encoding_header_json1", methods=["GET"]) | ||
def response_with_content_encoding_1(): | ||
return Response( | ||
response=gzip.compress(json.dumps({"some": "data"}).encode()), | ||
mimetype="application/json", | ||
headers={"Content-Encoding": "gzip"}, | ||
) | ||
|
||
|
||
@app.route("/content_encoding_header_textarbitrary1", methods=["GET"]) | ||
def response_with_content_encoding_2(): | ||
return Response( | ||
response=b"OK", | ||
mimetype="text/arbitrary", | ||
headers={"Content-Encoding": "something_arbitrarily_binary"}, | ||
) | ||
|
||
|
||
@app.route("/content_encoding_header_textarbitrary2", methods=["GET"]) | ||
def response_with_content_encoding_3(): | ||
return Response( | ||
response="OK", | ||
mimetype="text/arbitrary", | ||
headers={"Content-Encoding": "with_content_type_but_not_bytes_response"}, | ||
) | ||
|
||
|
||
@app.route("/userdefined_additional_mimetype_response1", methods=["GET"]) | ||
def response_with_userdefined_addtional_mimetype(): | ||
return Response( | ||
response="OK", | ||
mimetype="application/vnd.oai.openapi", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.