about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-12-11 09:05:08 +0000
committerEric Wong <normalperson@yhbt.net>2011-12-11 09:05:08 +0000
commit246bc4139262d4575b3a7b45e7a08bc93ff1a975 (patch)
tree365a7d22202a4cd66411e1ca38c4695cee669ccc
parent3f342091cec9fcd5f99ba934444f17cd0c77de71 (diff)
downloadmogilefs-client-246bc4139262d4575b3a7b45e7a08bc93ff1a975.tar.gz
The client-provided Content-MD5 may have leading/trailing
whitespace, so we shall strip that before comparing.

We also know any base64-encoded MD5 we generate will have only
trailing whitespace so we can get away with the (slightly)
faster and more-GC-friendly String#rstrip!
-rw-r--r--lib/mogilefs/chunker.rb5
1 files changed, 2 insertions, 3 deletions
diff --git a/lib/mogilefs/chunker.rb b/lib/mogilefs/chunker.rb
index baddcae..0d5c627 100644
--- a/lib/mogilefs/chunker.rb
+++ b/lib/mogilefs/chunker.rb
@@ -20,15 +20,14 @@ class MogileFS::Chunker
 
   def flush
     if @md5
-      content_md5 = [ @md5.digest ].pack('m').strip
+      content_md5 = [ @md5.digest ].pack('m').rstrip!
       if @expect_md5.respond_to?(:call)
-        expect = @expect_md5.call
+        expect = @expect_md5.call.strip
         if expect != content_md5
           raise MogileFS::ChecksumMismatchError,
             "expected: #{expect.inspect} actual: #{content_md5.inspect}"
         end
       end
-      warn "Content-MD5: #{content_md5}\r\n" if $DEBUG
       @io.write("0\r\nContent-MD5: #{content_md5}\r\n\r\n")
     else
       @io.write("0\r\n\r\n")