Skip to content

Instantly share code, notes, and snippets.

@stavinsky
Created October 5, 2014 14:38
Show Gist options
  • Save stavinsky/30ab813f5aa3e394a0f9 to your computer and use it in GitHub Desktop.
Save stavinsky/30ab813f5aa3e394a0f9 to your computer and use it in GitHub Desktop.
cherrypy if-modified-since example
import time
import cherrypy
now = [2014, 10, 4, 20, 45, 41, 5, 277, 0]
class Root():
def index(self):
cherrypy.response.headers['Last-Modified'] = cherrypy.lib.httputil.HTTPDate(time.mktime(tuple(now)))
cherrypy.lib.cptools.validate_since()
return 'Hello world'
# example of converting date from datetime to time sctuct:
import time
from datetime import datetime
now = datetime.now()
now_st = time.mktime(now.timetuple())
# example from http://stackoverflow.com/questions/3453177/convert-python-datetime-to-rfc-2822
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment