[logback-dev] svn commit: r1477 - in logback/trunk/logback-access/src/main/java/ch/qos/logback/access: . servlet spi

noreply.ceki at qos.ch noreply.ceki at qos.ch
Wed Mar 28 20:41:36 CEST 2007


Author: ceki
Date: Wed Mar 28 20:41:36 2007
New Revision: 1477

Modified:
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/Constants.java
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/servlet/Util.java
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/spi/AccessEvent.java

Log:
- We now avoid polluting the output with image contents which most of the time look like gibberish anyhow.

Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/Constants.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/Constants.java	(original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/Constants.java	Wed Mar 28 20:41:36 2007
@@ -5,4 +5,9 @@
   public static final String LB_OUTPUT_BUFFER = "LB_OUTPUT_BUFFER";
   
   public final static String X_WWW_FORM_URLECODED = "application/x-www-form-urlencoded";
+  
+  public final static String IMAGE_CONTENT_TYPE = "image/";
+  public final static String IMAGE_JPEG = "image/jpeg";
+  public final static String IMAGE_GIF = "image/gif";
+  public final static String IMAGE_PNG = "image/png";
 }

Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/servlet/Util.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/servlet/Util.java	(original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/servlet/Util.java	Wed Mar 28 20:41:36 2007
@@ -1,6 +1,7 @@
 package ch.qos.logback.access.servlet;
 
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 
 import ch.qos.logback.access.Constants;
 
@@ -14,4 +15,15 @@
       return false;
     }
   }
+  
+  public static boolean isImageResponse(HttpServletResponse response) {
+    
+    String responseType = response.getContentType();
+    
+    if (responseType != null && responseType.startsWith(Constants.IMAGE_CONTENT_TYPE)) {
+      return true;
+    } else {
+      return false;
+    }
+  }
 }

Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/spi/AccessEvent.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/spi/AccessEvent.java	(original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/spi/AccessEvent.java	Wed Mar 28 20:41:36 2007
@@ -330,24 +330,23 @@
 
     if (Util.isFormUrlEncoded(httpRequest)) {
       StringBuffer buf = new StringBuffer();
-      
+
       Enumeration pramEnumeration = httpRequest.getParameterNames();
 
       // example: id=1234&user=cgu
-      //          number=1233&x=1
+      // number=1233&x=1
       int count = 0;
       try {
-        while(pramEnumeration.hasMoreElements()) {
-          
-        
-        String key = (String) pramEnumeration.nextElement();
+        while (pramEnumeration.hasMoreElements()) {
+
+          String key = (String) pramEnumeration.nextElement();
           if (count++ != 0) {
             buf.append("&");
           }
           buf.append(key);
           buf.append("=");
           String val = httpRequest.getParameter(key);
-          if(val != null) {
+          if (val != null) {
             buf.append(val);
           } else {
             buf.append("");
@@ -380,16 +379,21 @@
     if (responseContent != null) {
       return responseContent;
     }
-    // retreive the byte array previously placed by TeeFilter
-    byte[] outputBuffer = (byte[]) httpRequest
-        .getAttribute(Constants.LB_OUTPUT_BUFFER);
 
-    if (outputBuffer != null) {
-      responseContent = new String(outputBuffer);
-    }
+    if (Util.isImageResponse(httpResponse)) {
+      responseContent = "[IMAGE CONTENTS SUPPRESSED]";
+    } else {
 
-    if (responseContent == null || responseContent.length() == 0) {
-      responseContent = EMPTY;
+      // retreive the byte array previously placed by TeeFilter
+      byte[] outputBuffer = (byte[]) httpRequest
+          .getAttribute(Constants.LB_OUTPUT_BUFFER);
+
+      if (outputBuffer != null) {
+        responseContent = new String(outputBuffer);
+      }
+      if (responseContent == null || responseContent.length() == 0) {
+        responseContent = EMPTY;
+      }
     }
 
     return responseContent;



More information about the logback-dev mailing list