Skip to content

Instantly share code, notes, and snippets.

@ruckus
Created August 12, 2009 01:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruckus/166249 to your computer and use it in GitHub Desktop.
Save ruckus/166249 to your computer and use it in GitHub Desktop.
class ExpiresXHRRequests
def initialize(app)
@app = app
end
def call(env)
is_xhr = env['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'
status, headers, body = @app.call(env)
if is_xhr && !headers.has_key?('Expires') # only set if NOT already set
headers['Expires'] = "#{one_week_ago.strftime('%a, %d %b %Y %H:%M:%S GMT')}"
end
[status, headers, body]
end
private
def one_week_ago
Time.now - (60 * 60 * 24 * 7)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment