Skip to content

Commit

Permalink
Adjust path handling for robots.txt and favicon.ico (#33)
Browse files Browse the repository at this point in the history
* Adjust path handling for robots.txt and favicon.ico

* Add a shorter description

* Add tests

* Update changelog

Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
  • Loading branch information
asriniva and di committed Apr 13, 2020
1 parent 9fd5585 commit 71914a3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/functions_framework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("/<path:path>", 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(
Expand Down
13 changes: 13 additions & 0 deletions tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 71914a3

Please sign in to comment.