store upload time in stored file and test Last-Modified header
authorLunar <lunar@anargeek.net>
Sat, 7 Aug 2010 09:23:55 +0000 (11:23 +0200)
committerLunar <lunar@anargeek.net>
Sat, 7 Aug 2010 13:20:05 +0000 (15:20 +0200)
README
coquelicot.rb
test_coquelicot.rb

diff --git a/README b/README
index 4b95763..c98a9ab 100644 (file)
--- a/README
+++ b/README
@@ -172,6 +172,7 @@ is fead using the former 'Salt' and the given passphrase.
 Once decrypted, content has the following format:
 
     --- 
+    Created-at: <upload time in seconds since epoch>
     Filename: "<original file name>"
     Content-Type: "<MIME type>"
     Length: <file length is bytes>
index 8009c5f..fe5f4fe 100644 (file)
@@ -43,19 +43,21 @@ class StoredFile
     @cipher = nil
   end
 
-  def mtime
-    @file.mtime
+  def created_at
+    Time.at(@meta['Created-at'])
   end
 
   def self.create(src, pass, meta)
     salt = gen_salt
     clear_meta = { "Coquelicot" => COQUELICOT_VERSION,
                    "Salt" => Base64.encode64(salt).strip,
-                   "Expire-at" => meta.delete('Expire-at') }
+                   "Expire-at" => meta.delete('Expire-at'),
+                 }
     yield YAML.dump(clear_meta) + YAML_START
 
     cipher = get_cipher(pass, salt, :encrypt)
-    yield cipher.update(YAML.dump(meta) + YAML_START)
+    yield cipher.update(YAML.dump(meta.merge("Created-at" => Time.now.to_i)) +
+                        YAML_START)
     src.rewind
     while not (buf = src.read(BUFFER_LEN)).nil?
       yield cipher.update(buf)
@@ -382,7 +384,7 @@ def send_stored_file(link, pass)
   return false if file.nil?
   return expired if Time.now > file.expire_at
 
-  last_modified file.mtime.httpdate
+  last_modified file.created_at.httpdate
   attachment file.meta['Filename']
   response['Content-Length'] = "#{file.meta['Length']}"
   response['Content-Type'] = file.meta['Content-Type'] || 'application/octet-stream'
index d6fbf39..1b7ef10 100644 (file)
@@ -57,6 +57,15 @@ describe 'Coquelicot' do
     last_response.body.should eql(File.new(__FILE__).read)
   end
 
+  it "should correctly set Last-Modified header when downloading" do
+    url = upload
+    get url
+    last_modified = last_response['Last-Modified']
+    last_modified.should_not be_nil
+    get url
+    last_response['Last-Modified'].should eql(last_modified)
+  end
+
   it "should prevent upload without a password" do
     url = upload :upload_password => ''
     url.should be_nil