Skip to content

Commit 71914a3

Browse files
asrinivadi
andauthored
Adjust path handling for robots.txt and favicon.ico (#33)
* Adjust path handling for robots.txt and favicon.ico * Add a shorter description * Add tests * Update changelog Co-authored-by: Dustin Ingram <[email protected]>
1 parent 9fd5585 commit 71914a3

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [Unreleased]
88
- Add support for running `python -m functions_framework` ([#31])
99
- Move `functions_framework.cli.cli` to `functions_framework._cli._cli`
10+
- Adjust path handling for robots.txt and favicon.ico ([#33])
1011

1112
## [1.2.0] - 2020-02-20
1213
### Added
@@ -43,6 +44,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4344
[1.0.1]: https://github.com/GoogleCloudPlatform/functions-framework-python/releases/tag/v1.0.1
4445
[1.0.0]: https://github.com/GoogleCloudPlatform/functions-framework-python/releases/tag/v1.0.0
4546

47+
[#33]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/33
4648
[#31]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/31
4749
[#20]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/20
4850
[#14]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/14

src/functions_framework/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,11 @@ def create_app(target=None, source=None, signature_type=None):
174174
app.url_map.add(
175175
werkzeug.routing.Rule("/", defaults={"path": ""}, endpoint="run")
176176
)
177+
app.url_map.add(werkzeug.routing.Rule("/robots.txt", endpoint="error"))
178+
app.url_map.add(werkzeug.routing.Rule("/favicon.ico", endpoint="error"))
177179
app.url_map.add(werkzeug.routing.Rule("/<path:path>", endpoint="run"))
178180
app.view_functions["run"] = _http_view_func_wrapper(function, flask.request)
181+
app.view_functions["error"] = lambda: flask.abort(404, description="Not Found")
179182
elif signature_type == "event":
180183
app.url_map.add(
181184
werkzeug.routing.Rule(

tests/test_functions.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,3 +376,16 @@ def test_http_function_all_methods(method, data):
376376

377377
assert resp.status_code == 200
378378
assert resp.data == data
379+
380+
381+
@pytest.mark.parametrize("path", ["robots.txt", "favicon.ico"])
382+
def test_error_paths(path):
383+
source = TEST_FUNCTIONS_DIR / "http_trigger" / "main.py"
384+
target = "function"
385+
386+
client = create_app(target, source).test_client()
387+
388+
resp = client.get("/{}".format(path))
389+
390+
assert resp.status_code == 404
391+
assert b"Not Found" in resp.data

0 commit comments

Comments
 (0)