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 diff --git a/src/functions_framework/__init__.py b/src/functions_framework/__init__.py index 11ce9dd4..95e58d6a 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, description="Not Found") elif signature_type == "event": app.url_map.add( werkzeug.routing.Rule( 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