title: Set response headers in CQ5/AEM
body: <p>We need to set below response headers in CQ5/AEM based application.</p>
  
  <p><strong>Http Header: Frame options    Set X-Frame-Options: SAME ORIGIN
  Http Header: Strict Transport Security  Strict-Transport-Security: max-age=10886400; includeSubDomains; preload</strong></p>
  
  <p>I have done like these changes in my prior application using servlet filter to intercept the request. Similarly I tried to use the SlingFilter for this application. However it seems to be called many times for each request (when it download js,css,json files etc). Please see below code snippet,</p>
  
  <pre><code>@SlingFilter(scope = SlingFilterScope.COMPONENT, order = Integer.MIN_VALUE)
  @Properties({
  
      @Property(name="pattern",value="/soni/template/", propertyPrivate=false) 
  })
  public class ResponseHeaderFilter implements Filter {
  @Override
      public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
              throws IOException, ServletException {
  
          try {
  
                  HttpServletResponse httpResponse = (HttpServletResponse)response;        
                  httpResponse.setHeader("Strict-Transport-Security", "max-age=10886400; includeSubDomains");
                  filterChain.doFilter(request, httpResponse);
                  httpResponse.setHeader("X-Frame-Options", "SAMEORIGIN");
  
          } catch (Exception e) {                 
              e.printStackTrace();
          }        
  
      }
  </code></pre>
  
  <p>Is this the right way to do it in CQ5/AEM? How do I restrict this to once per page request?
  or is there better way to do it like configuration at dispatcher etc?</p>