|
39 | 39 |
|
40 | 40 | DEFAULT_SOURCE = os.path.realpath("./main.py")
|
41 | 41 | DEFAULT_SIGNATURE_TYPE = "http"
|
| 42 | +MAX_CONTENT_LENGTH = 10 * 1024 * 1024 |
42 | 43 |
|
43 | 44 |
|
44 | 45 | class _EventType(enum.Enum):
|
@@ -162,6 +163,16 @@ def view_func(path):
|
162 | 163 | return view_func
|
163 | 164 |
|
164 | 165 |
|
| 166 | +def read_request(response): |
| 167 | + """ |
| 168 | + Force the framework to read the entire request before responding, to avoid |
| 169 | + connection errors when returning prematurely. |
| 170 | + """ |
| 171 | + |
| 172 | + flask.request.get_data() |
| 173 | + return response |
| 174 | + |
| 175 | + |
165 | 176 | def create_app(target=None, source=None, signature_type=None):
|
166 | 177 | # Get the configured function target
|
167 | 178 | target = target or os.environ.get("FUNCTION_TARGET", "")
|
@@ -218,6 +229,7 @@ def create_app(target=None, source=None, signature_type=None):
|
218 | 229 | spec.loader.exec_module(source_module)
|
219 | 230 |
|
220 | 231 | app = flask.Flask(target, template_folder=template_folder)
|
| 232 | + app.config["MAX_CONTENT_LENGTH"] = MAX_CONTENT_LENGTH |
221 | 233 |
|
222 | 234 | # Extract the target function from the source file
|
223 | 235 | try:
|
@@ -250,6 +262,7 @@ def create_app(target=None, source=None, signature_type=None):
|
250 | 262 | app.url_map.add(werkzeug.routing.Rule("/<path:path>", endpoint="run"))
|
251 | 263 | app.view_functions["run"] = _http_view_func_wrapper(function, flask.request)
|
252 | 264 | app.view_functions["error"] = lambda: flask.abort(404, description="Not Found")
|
| 265 | + app.after_request(read_request) |
253 | 266 | elif signature_type == "event" or signature_type == "cloudevent":
|
254 | 267 | app.url_map.add(
|
255 | 268 | werkzeug.routing.Rule(
|
|
0 commit comments