Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LGA-3479: Disallow search engine indexing #191

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/main/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from app.main import routes # noqa: E402,F401
from app.main import filters # noqa: E402,F401
from app.main import middleware # noqa: E402,F401


def get_locale():
Expand Down
8 changes: 8 additions & 0 deletions app/main/middleware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from app.main import bp


@bp.after_app_request
def add_noindex_header(response):
"""Add a noindex header to all responses, to disallow search engines from indexing the page."""
response.headers["X-Robots-Tag"] = "noindex"
return response
19 changes: 19 additions & 0 deletions tests/unit_tests/test_middleware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pytest


@pytest.mark.parametrize(
"endpoint",
[
"/",
"/children-families-relationships",
"/cookies",
"/assets/images/favicon.svg",
"/assets/scripts.js",
"/assets/styles.css",
"/404-page",
"/service-unavailable",
],
)
def test_noindex_header_on_routes(client, endpoint):
response = client.get(endpoint)
assert response.headers.get("X-Robots-Tag") == "noindex"
Loading