app/main/views/index.py module contains all HTTP route handlers for the Document Download Frontend, managing document access, email verification, and service information.
Health Check Routes
status
Health check endpoint returning application status. Route:GET /_status
Always returns “ok”
Always returns 200
Service Routes
services
Redirects legacy service document URLs to the Document Download API. Routes:GET /services/_statusGET /services/<uuid:service_id>/documents/<uuid:document_id>GET /services/<uuid:service_id>/documents/<uuid:document_id>.<extension>GET /services/<uuid:service_id>/documents/<uuid:document_id>/check
Service identifier (optional)
Document identifier (optional)
File extension (optional)
Permanent redirect to DOCUMENT_DOWNLOAD_API_HOST_NAME with same path and query string
security_policy
Redirects to GOV.UK security.txt for vulnerability disclosure. Routes:GET /.well-known/security.txtGET /security.txt
Document Access Routes
landing
Document landing page with service information and download link. Route:GET /d/<base64_uuid:service_id>/<base64_uuid:document_id>
Base64-encoded service UUID
Base64-encoded document UUID
Document decryption key (query parameter)
Rendered landing page template
- Validates decryption key presence (404 if missing)
- Fetches service details and contact information
- Retrieves document metadata
- Redirects to email confirmation if
confirm_email=truein metadata - Otherwise redirects to direct download
- Returns 404/410 with
file-unavailable.htmltemplate for missing/expired documents
confirm_email_address
Email verification page for secure document access. Route:GET/POST /d/<base64_uuid:service_id>/<base64_uuid:document_id>/confirm-email-address
Base64-encoded service UUID
Base64-encoded document UUID
Document decryption key
Email address to verify (POST only)
Email confirmation form or redirect to download
- Displays email address form
- Redirects to download if metadata has
confirm_email=false
- Validates email address format
- Calls
_authenticate_access_to_documentAPI - Sets secure
document_access_signed_datacookie with domain scope - Redirects to download page on success
- Shows form error if email doesn’t match
- 429 Too Many Requests: Rate limit exceeded, shows retry message
- 400/403: Invalid email address, shows form error
- Returns 400 status code if form has validation errors
download_document
Document download page with file details and download link. Route:GET /d/<base64_uuid:service_id>/<base64_uuid:document_id>/download
Base64-encoded service UUID
Base64-encoded document UUID
Document decryption key
Download page with file information and direct download link
download_link: Direct file URL from metadatafile_size: Formatted file size (e.g., “2.5 MB”)file_type: Human-readable file type (e.g., “PDF”)service_name: Service name for contextservice_contact_info: Contact link or emailfile_expiry_date: Formatted expiry date (if available)
- Returns 404/410 with
file-unavailable.htmlfor missing/expired documents
Helper Functions
_format_file_expiry_date
Formats ISO date string to human-readable expiry date.ISO 8601 datetime string
Formatted date with optional day of week
- Includes day of week if expiry within 30 days:
"Monday 15 March 2026" - Otherwise only date:
"15 March 2026" - Removes leading zeros from day
_get_service_or_raise_error
Fetches service details from API with error handling.Service identifier
Service data with name and contact_link
- Calls
service_api_client.get_service(service_id) - Aborts with HTTP status code from API on HTTPError
_get_document_metadata
Retrieves document metadata from Document Download API.Service identifier
Document identifier
Decryption key
Document metadata including file URL, size, type, and expiry
direct_file_url: Download URLsize_in_bytes: File size in bytesfile_extension: File extension (e.g., “.pdf”)available_until: ISO datetime string or nullconfirm_email: Boolean for email verification requirement
- 400: Invalid/missing decryption key → 404
- 403/404: Document not found → 404
- 410: Document expired → 410
- 500+: Raises for status (handled by global error handler)
- Validates
available_untilexpiry, aborts 410 if expired
_authenticate_access_to_document
Authenticates email address for document access.Service identifier
Document identifier
Decryption key
Email address to authenticate
Authentication data with signed_data and cookie_path, or None if authentication failed
- 429: Raises
TooManyRequestsexception - 400/403: Returns
None(invalid email) - 500+: Raises for status (handled by global error handler)