From 246bc4139262d4575b3a7b45e7a08bc93ff1a975 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 11 Dec 2011 09:05:08 +0000 Subject: chunker: small cleanups to whitespace handling 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! --- lib/mogilefs/chunker.rb | 5 ++--- 1 file 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") -- cgit v1.2.3-24-ge0c7