Skip to content

Instantly share code, notes, and snippets.

@wil
Created March 29, 2010 08:25
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wil/347596 to your computer and use it in GitHub Desktop.
Save wil/347596 to your computer and use it in GitHub Desktop.
Django Setting Expires Header in XHR Response
import time
from django.utils.http import http_date
AJAX_NEGATIVE_CHECK_EXPIRES = 60 # object is still available
AJAX_POSITIVE_CHECK_EXPIRES = 60*10 # if object is not available (or taken)
def check_ajax(request):
# do stuff here
timeout = AJAX_NEGATIVE_CHECK_EXPIRES if avail else AJAX_POSITIVE_CHECK_EXPIRES
response = HttpResponse(json_result, mimetype='application/json')
response['Expires'] = http_date(time.time() + timeout)
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment