Skip to content

Commit d4bb7d0

Browse files
committed
Make (error) response on /openeo/x.y/.well-known/openeo more cache-friendly
give error body a static request id (just based on current request) to avoid confusion ref: eu-cdse/openeo-cdse-infra#750
1 parent b0b1502 commit d4bb7d0

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

openeo_driver/testing.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def text(self) -> str:
123123
def headers(self) -> Headers:
124124
return self.response.headers
125125

126-
def assert_status_code(self, status_code: int) -> 'ApiResponse':
126+
def assert_http_status_code(self, status_code: int) -> "ApiResponse":
127127
"""Check HTTP status code"""
128128
if self.status_code != status_code:
129129
message = f"Expected response with status code {status_code} but got {self.status_code}."
@@ -132,6 +132,8 @@ def assert_status_code(self, status_code: int) -> 'ApiResponse':
132132
raise ApiException(message)
133133
return self
134134

135+
assert_status_code = assert_http_status_code
136+
135137
def assert_content(self) -> 'ApiResponse':
136138
"""Assert that the response body is not empty"""
137139
# TODO: also check content type? also check (prefix of) data?

openeo_driver/views.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,10 @@ def udf_runtimes():
524524
@blueprint.route('/.well-known/openeo')
525525
def versioned_well_known_openeo():
526526
# Clients might request this for version discovery. Avoid polluting (error) logs by explicitly handling this.
527-
error = NotFoundException(message="Not a well-known openEO URI")
527+
error = NotFoundException(
528+
message="Not a well-known openEO URI",
529+
id="r-" + re.sub("[^a-z0-9]+", "", flask.request.path, flags=re.I),
530+
)
528531
return make_response(jsonify(error.to_dict()), error.status_code)
529532

530533
@blueprint.route('/CHANGELOG', methods=['GET'])

tests/test_views.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,14 @@ def test_well_known_openeo(self, client):
191191
assert resp.headers["Cache-Control"] == "max-age=900, public"
192192

193193
def test_versioned_well_known_openeo(self, api):
194-
api.get("/.well-known/openeo").assert_error(404, "NotFound")
194+
resp = api.get("/.well-known/openeo")
195+
resp.assert_http_status_code(404)
196+
short_api_version = api.api_version.replace(".", "")
197+
assert resp.json == {
198+
"code": "NotFound",
199+
"id": f"r-openeo{short_api_version}wellknownopeneo",
200+
"message": "Not a well-known openEO URI",
201+
}
195202

196203
@pytest.mark.parametrize(
197204
["headers", "expected"],

0 commit comments

Comments
 (0)