title: Servlet response wrapper implementation leads to empty response
body: <p>I tried to implement servlet response wrapper to modify the response.
  My goal is to add couple of  tags within html </p>
  <p>This code works fine and  tags are properly added to html.
  But the problem is that everything works  expected in non-IE7 browsers.
  IE9/Firefox dont have any issues at all. Even IE7 from other's desktops dont have a problem. Only my IE7 browser have this issue, it simply displays empty page - complete white screen.
  Even right-click view source displays html with empty head/body.</p>
  <p>Through Fiddler I see response code is 200, but content length is 0.</p>
  <p>If I do F5 twice simultaneously, Fidder shows this error</p>
  <blockquote>
  <p>Fiddler has detected a protocol violation in session #3.</p>
  <p>The Server did not return properly formatted HTTP Headers. HTTP headers
  should be terminated with CRLFCRLF. These were terminated with LFLF.</p>
  </blockquote>
  <p>I am not manipulating any header attributes. Though it works everywhere else other than my browser, I want to know what is the problem as we cannot predict how browsers are out there just like mine.</p>
  <p>Here is my code.</p>
  <pre><code>    HttpServletRequest httpServletRequest   = (HttpServletRequest)request;
      HttpServletResponse httpServletResponse = (HttpServletResponse)response;
      BrowserRequestWrapper requestWrapper    = new BrowserRequestWrapper(httpServletRequest);
      BrowserResponseWrapper responseWrapper  = new BrowserResponseWrapper(httpServletResponse);
      PrintWriter responsePrintWriter         = response.getWriter();
      filterChain.doFilter(requestWrapper,responseWrapper);
      try {           
          String responseString       = responseWrapper.toString();           
          String processedResponse    = getProcessedResponse(responseString);         
          response.setContentLength( processedResponse.length() );
          
          responsePrintWriter.write(processedResponse);
          //responsePrintWriter.flush();
          responsePrintWriter.close();
      } catch (Throwable t) {
          Logger.getLocation().errorT(&quot;doFilter&quot;,&quot;An exception has occured&quot;);
          Logger.getStackTrace(t);
      }   
  </code></pre>
  <p>Here is wrapper class.</p>
  <pre><code>public class BrowserResponseWrapper extends HttpServletResponseWrapper {
  private CharArrayWriter output;
  
  public String toString() {
      return output.toString();
  }
  public BrowserResponseWrapper(HttpServletResponse response){
      super(response);
      output = new CharArrayWriter();
  }
  
  public PrintWriter getWriter(){     
      return new PrintWriter(output);
  }
  }
  </code></pre>