From d62003b0e4c81a7f7bbdd8daf9dad591071d09d7 Mon Sep 17 00:00:00 2001 From: Arjun Srinivasan <69502+asriniva@users.noreply.github.com> Date: Fri, 10 Apr 2020 18:44:11 +0000 Subject: [PATCH 1/4] Adjust path handling for robots.txt and favicon.ico --- src/functions_framework/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/functions_framework/__init__.py b/src/functions_framework/__init__.py index 11ce9dd4..7d0365ce 100644 --- a/src/functions_framework/__init__.py +++ b/src/functions_framework/__init__.py @@ -174,8 +174,11 @@ def create_app(target=None, source=None, signature_type=None): app.url_map.add( werkzeug.routing.Rule("/", defaults={"path": ""}, endpoint="run") ) + app.url_map.add(werkzeug.routing.Rule("/robots.txt", endpoint="error")) + app.url_map.add(werkzeug.routing.Rule("/favicon.ico", endpoint="error")) app.url_map.add(werkzeug.routing.Rule("/", endpoint="run")) app.view_functions["run"] = _http_view_func_wrapper(function, flask.request) + app.view_functions["error"] = lambda: flask.abort(404) elif signature_type == "event": app.url_map.add( werkzeug.routing.Rule( From 374597fa28c179d421f701ab2d61b8198dbb3bd1 Mon Sep 17 00:00:00 2001 From: Dustin Ingram Date: Mon, 13 Apr 2020 13:22:25 -0500 Subject: [PATCH 2/4] Add a shorter description --- src/functions_framework/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions_framework/__init__.py b/src/functions_framework/__init__.py index 7d0365ce..95e58d6a 100644 --- a/src/functions_framework/__init__.py +++ b/src/functions_framework/__init__.py @@ -178,7 +178,7 @@ def create_app(target=None, source=None, signature_type=None): app.url_map.add(werkzeug.routing.Rule("/favicon.ico", endpoint="error")) app.url_map.add(werkzeug.routing.Rule("/", endpoint="run")) app.view_functions["run"] = _http_view_func_wrapper(function, flask.request) - app.view_functions["error"] = lambda: flask.abort(404) + app.view_functions["error"] = lambda: flask.abort(404, description="Not Found") elif signature_type == "event": app.url_map.add( werkzeug.routing.Rule( From 784e8643ff6af7f8a12469af268086eab46260c1 Mon Sep 17 00:00:00 2001 From: Dustin Ingram Date: Mon, 13 Apr 2020 13:22:34 -0500 Subject: [PATCH 3/4] Add tests --- tests/test_functions.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/test_functions.py b/tests/test_functions.py index 24384bf5..5c7250b8 100644 --- a/tests/test_functions.py +++ b/tests/test_functions.py @@ -376,3 +376,16 @@ def test_http_function_all_methods(method, data): assert resp.status_code == 200 assert resp.data == data + + +@pytest.mark.parametrize("path", ["robots.txt", "favicon.ico"]) +def test_error_paths(path): + source = TEST_FUNCTIONS_DIR / "http_trigger" / "main.py" + target = "function" + + client = create_app(target, source).test_client() + + resp = client.get("/{}".format(path)) + + assert resp.status_code == 404 + assert b"Not Found" in resp.data From c4c325eab36a33e1af6daa7ca49f749bbf1e9b66 Mon Sep 17 00:00:00 2001 From: Dustin Ingram Date: Mon, 13 Apr 2020 13:23:57 -0500 Subject: [PATCH 4/4] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cacc025f..aa11fb39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - Add support for running `python -m functions_framework` ([#31]) - Move `functions_framework.cli.cli` to `functions_framework._cli._cli` +- Adjust path handling for robots.txt and favicon.ico ([#33]) ## [1.2.0] - 2020-02-20 ### Added @@ -43,6 +44,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [1.0.1]: https://github.com/GoogleCloudPlatform/functions-framework-python/releases/tag/v1.0.1 [1.0.0]: https://github.com/GoogleCloudPlatform/functions-framework-python/releases/tag/v1.0.0 +[#33]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/33 [#31]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/31 [#20]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/20 [#14]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/14