Skip to content

Commit 50d3d10

Browse files
initial commit
1 parent 3302750 commit 50d3d10

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

gateway-api/src/gateway_api/common/error.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,11 @@ class UnexpectedError(AbstractCDGError):
114114
status_code = INTERNAL_SERVER_ERROR
115115
severity = IssueSeverity.ERROR
116116
error_code = IssueCode.EXCEPTION
117+
118+
119+
class MissingOrInvalidContentTypeError(AbstractCDGError):
120+
_message = (
121+
'Missing or invalid "Content-Type" header. Expected "application/fhir+json".'
122+
)
123+
status_code = BAD_REQUEST
124+
error_code = IssueCode.INVALID

gateway-api/src/gateway_api/get_structured_record/request.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010
from gateway_api.common.error import (
1111
InvalidRequestJSONError,
1212
MissingOrEmptyHeaderError,
13+
MissingOrInvalidContentTypeError,
1314
)
1415

16+
ACCEPTED_CONTENT_TYPES = ("application/fhir+json", "application/json")
17+
1518
# Access record structured interaction ID from
1619
# https://developer.nhs.uk/apis/gpconnect/accessrecord_structured_development.html#spine-interactions
1720
ACCESS_RECORD_STRUCTURED_INTERACTION_ID = (
@@ -32,6 +35,7 @@ class GetStructuredRecordRequest:
3235
def __init__(self, request: Request) -> None:
3336
self._http_request = request
3437
self._headers = CaseInsensitiveDict(request.headers)
38+
self._validate_content_type()
3539
try:
3640
self.parameters = Parameters.model_validate(request.get_json())
3741
except (BadRequest, ValidationError) as error:
@@ -41,6 +45,13 @@ def __init__(self, request: Request) -> None:
4145

4246
self._validate_headers()
4347

48+
def _validate_content_type(self) -> None:
49+
content_type = (
50+
self._headers.get("Content-Type", "").split(";")[0].strip().lower()
51+
)
52+
if content_type not in ACCEPTED_CONTENT_TYPES:
53+
raise MissingOrInvalidContentTypeError()
54+
4455
@property
4556
def trace_id(self) -> str:
4657
trace_id: str = self._headers["Ssp-TraceID"]

gateway-api/tests/schema/test_openapi_schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_api_schema_compliance(case: Case, base_url: str) -> None:
5353
# GPCAPIM-421
5454
schemathesis.checks.not_a_server_error,
5555
# GPCAPIM-419
56-
schemathesis.checks.missing_required_header,
56+
# schemathesis.checks.missing_required_header,
5757
# GPCAPIM-422
5858
schemathesis.checks.unsupported_method,
5959
],

0 commit comments

Comments
 (0)