module Sinatra::Helpers

def last_modified(time)

'304 Not Modified' response.
matches the time specified, execution is immediately halted with a
When the current request includes an 'If-Modified-Since' header that

DateTime, or other object that responds to +to_time+.
and halt if conditional GET matches. The +time+ argument is a Time,
Set the last modified time of the resource (HTTP 'Last-Modified' header)
def last_modified(time)
  time = time.to_time if time.respond_to?(:to_time)
  time = time.httpdate if time.respond_to?(:httpdate)
  response['Last-Modified'] = time
  halt 304 if time == request.env['HTTP_IF_MODIFIED_SINCE']
  time
end