feat: exposed 'Date' header so clients can compute accurate relative time (#26979) REV-2126
Exposed the Date header so clients can accurately compute times relative to the dates returned by the API; browser time is notoriously unreliable for this, especially for a Learner-facing countdown call-to-action based on the access expiration date. (REV-2126) Using the Date header for this allows the client to make use of information that is already sent, does not require additional calls nor modifying the API, and could be generalized to more or all our APIs without modifying them.
This commit is contained in:
@@ -441,6 +441,17 @@ class CoursewareInformation(RetrieveAPIView):
|
||||
context['requested_fields'] = self.request.GET.get('requested_fields', None)
|
||||
return context
|
||||
|
||||
def finalize_response(self, request, response, *args, **kwargs):
|
||||
"""
|
||||
Return the final response, exposing the 'Date' header for computing relative time to the dates in the data.
|
||||
"""
|
||||
response = super().finalize_response(request, response, *args, **kwargs)
|
||||
# Adding this header should be moved somewhere global, not just this endpoint
|
||||
exposedHeaders = response.get('Access-Control-Expose-Headers', '')
|
||||
exposedHeaders += ', Date' if exposedHeaders else 'Date'
|
||||
response['Access-Control-Expose-Headers'] = exposedHeaders
|
||||
return response
|
||||
|
||||
|
||||
class SequenceMetadata(DeveloperErrorViewMixin, APIView):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user