Skip to content

Commit

Permalink
Fix the /robots.txt response
Browse files Browse the repository at this point in the history
Instead of newlines it was returning the text \n.
Content type was set to application/json instead of text/plain.
  • Loading branch information
omad committed Jun 19, 2024
1 parent 54afe1f commit fb0aead
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
8 changes: 5 additions & 3 deletions cubedash/_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from datacube.model import DatasetType, Range
from datacube.scripts.dataset import build_dataset_info
from dateutil import tz
from flask import abort, redirect, request, url_for
from flask import abort, make_response, redirect, request, url_for
from werkzeug.datastructures import MultiDict
from werkzeug.exceptions import HTTPException

Expand Down Expand Up @@ -680,9 +680,11 @@ def about_page():

@app.route("/robots.txt")
def robots_txt():
return utils.as_json(
flask.current_app.config.get("ROBOTS_TXT", _ROBOTS_TXT_DEFAULT)
resp = make_response(
flask.current_app.config.get("ROBOTS_TXT", _ROBOTS_TXT_DEFAULT), 200
)
resp.headers["Content-Type"] = "text/plain"
return resp


@app.route("/")
Expand Down
9 changes: 8 additions & 1 deletion integration_tests/test_page_loads.py
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,14 @@ def test_get_robots(client: FlaskClient):
Check that robots.txt is correctly served from root
"""
text, rv = get_text_response(client, "/robots.txt")
assert "User-Agent: *" in text
assert "User-Agent:" in text

num_lines = len(text.split("\n"))
assert num_lines > 1, "robots.txt should have multiple lines"

assert (
rv.headers["Content-Type"] == "text/plain"
), "robots.txt content-type should be text/plain"


def test_all_give_404s(client: FlaskClient):
Expand Down

0 comments on commit fb0aead

Please sign in to comment.