feat: added another 'Date' expose-headers for outline api clients (#27221)

Exposed the Date header on the outline api so clients can accurately compute times relative to the dates returned by the API; this was previously done with the course API (#26979)

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:
Ben Holt
2021-04-02 10:37:19 -04:00
committed by GitHub
parent c4da6c1fe4
commit ec3c31eb05
3 changed files with 34 additions and 5 deletions

View File

@@ -213,3 +213,13 @@ def reset_course_deadlines(request):
referrer = request.META.get('HTTP_REFERER')
return redirect(referrer) if referrer else HttpResponse()
def expose_header(header, response):
"""
Add a header name to Access-Control-Expose-Headers to allow client code to access that header's value
"""
exposedHeaders = response.get('Access-Control-Expose-Headers', '')
exposedHeaders += f', {header}' if exposedHeaders else header
response['Access-Control-Expose-Headers'] = exposedHeaders
return response