View Javadoc

1   package com.atlassian.core.filters.legacy;
2   
3   import javax.servlet.http.HttpServletResponseWrapper;
4   import javax.servlet.http.HttpServletResponse;
5   
6   /**
7    * Legacy response wrapper which prevents the Content-Location header being set on the wrapped
8    * response.
9    * <p/>
10   * This was necessary for Orion application servers earlier than 2.0.2, which set the Content-
11   * Location header on JSPs automatically. Opera versions 7.x and 8.x used the header to resolve
12   * relative URLs, but this was reverted in Opera 9.
13   * <p/>
14   * This is here for legacy functionality, but its use is <b>not</b> recommended. Our applications
15   * no longer support the versions of Opera and Orion that need this fix.
16   *
17   * @since 4.0
18   */
19  public final class NoContentLocationHeaderResponseWrapper extends HttpServletResponseWrapper
20  {
21      public NoContentLocationHeaderResponseWrapper(HttpServletResponse response)
22      {
23          super(response);
24      }
25  
26      /**
27       * If the header name is "Content-Location", the header is not set. Otherwise, delegates
28       * to the wrapped response.
29       */
30      public void setHeader(String name, String value)
31      {
32          if (isContentLocationHeader(name))
33              return;
34          super.setHeader(name, value);
35      }
36  
37      /**
38       * If the header name is "Content-Location", the header is not added to. Otherwise,
39       * delegates to the wrapped response.
40       */
41      public void addHeader(String name, String value)
42      {
43          if (isContentLocationHeader(name))
44              return;
45          super.addHeader(name, value);
46      }
47  
48      private boolean isContentLocationHeader(String headerName)
49      {
50          return headerName != null && "content-location".equalsIgnoreCase(headerName);
51      }
52  }