From c1c7f6af38904a795cdb59ece5eef13ae9993cb5 Mon Sep 17 00:00:00 2001 From: hns Date: Thu, 21 Nov 2002 15:46:58 +0000 Subject: [PATCH] Moved auto-ETag generation out of String encoding block so that ETags are generated for binary responses. Some minor fixes in auto-ETag gen. --- src/helma/framework/ResponseTrans.java | 28 ++++++++++++++------------ 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/helma/framework/ResponseTrans.java b/src/helma/framework/ResponseTrans.java index 3f120192..51a73795 100644 --- a/src/helma/framework/ResponseTrans.java +++ b/src/helma/framework/ResponseTrans.java @@ -349,24 +349,26 @@ public final class ResponseTrans implements Externalizable { encodingError = true; response = buffer.toString ().getBytes (); } - // if etag is not set, calc MD5 digest and check it - if (etag == null && lastModified == -1 && - redir == null && error == null) try { - digest = MessageDigest.getInstance("MD5"); - byte[] b = digest.digest(response); - etag = "\""+new String (Base64.encode(b))+"\""; - if (reqtrans != null && reqtrans.hasETag (etag)) { - response = new byte[0]; - notModified = true; - } - } catch (Exception ignore) { - // Etag creation failed for some reason. Ignore. - } buffer = null; // make sure this is done only once, even with more requsts attached } else { response = new byte[0]; } } + // if etag is not set, calc MD5 digest and check it + if (etag == null && lastModified == -1 && + redir == null && cache && error == null) try { + digest = MessageDigest.getInstance("MD5"); + // if (contentType != null) + // digest.update (contentType.getBytes()); + byte[] b = digest.digest(response); + etag = "\""+new String (Base64.encode(b))+"\""; + if (reqtrans != null && reqtrans.hasETag (etag)) { + response = new byte[0]; + notModified = true; + } + } catch (Exception ignore) { + // Etag creation failed for some reason. Ignore. + } notifyAll (); // if there was a problem with the encoding, let the app know if (encodingError)