Skip to content

Instantly share code, notes, and snippets.

@eric
Created September 22, 2009 04:18
Show Gist options
  • Save eric/190807 to your computer and use it in GitHub Desktop.
Save eric/190807 to your computer and use it in GitHub Desktop.
From 784d6d5e405fa569e1b30a226b9230b94b9e43c4 Mon Sep 17 00:00:00 2001
From: Eric Lindvall <[email protected]>
Date: Mon, 21 Sep 2009 21:15:52 -0700
Subject: [PATCH] Don't use the sinatra etag helper
The etag() helper is adding extra quotes around the value (and we don't want
it to).
---
app/metal/hostess.rb | 15 +++++++++++++--
1 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/app/metal/hostess.rb b/app/metal/hostess.rb
index db81d16..19ce78a 100644
--- a/app/metal/hostess.rb
+++ b/app/metal/hostess.rb
@@ -19,8 +19,19 @@ class Hostess < Sinatra::Default
:if_none_match => env['HTTP_IF_NONE_MATCH'])
# These should raise a 304 if either of them match
- last_modified(result.response['last-modified']) if result.response['last-modified']
- etag(result.response['etag']) if result.response['etag']
+ if result.response['last-modified']
+ last_modified(result.response['last-modified'])
+ end
+
+ if value = result.response['etag']
+ response['ETag'] = value
+
+ # Conditional GET check
+ if etags = env['HTTP_IF_NONE_MATCH']
+ etags = etags.split(/\s*,\s*/)
+ halt 304 if etags.include?(value) || etags.include?('*')
+ end
+ end
# If we got a 304 back, let's give it back to the client
halt 304 if result.response.code == 304
--
1.6.4.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment