How to set response header for digital asset in AEM CQ6.1?
<p>I have a request that if a user directly accesses a .pdf asset(for example, <a href="http://localhost:4505/content/dam/company/us/en/962059.pdf" rel="nofollow">http://localhost:4505/content/dam/company/us/en/962059.pdf</a>)  from AEM CQ 6.1, I need to send a custom http respone header. This is what I wrote. This is only works if I open a .html page. But it doesn't work if I open a .pdf in browser. So what did I do wrong?</p>

<p>Thanks</p>

<pre><code>package com.mycompany.wcm.filter;


import org.apache.felix.scr.annotations.*;
import org.apache.felix.scr.annotations.sling.SlingFilter;
import org.apache.felix.scr.annotations.sling.SlingFilterScope;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.*;
import org.apache.sling.api.scripting.SlingBindings;
import org.apache.sling.api.scripting.SlingScriptHelper;
import org.apache.sling.runmode.RunMode;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.jcr.Session;
import javax.servlet.*;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@SlingFilter(
        label = "Sample Filter",
        description = "Sample Description",
        metatype = true,
        generateComponent = true, // True if you want to leverage activate/deactivate
        generateService = true,
        order = -501, // The smaller the number, the earlier in the Filter chain (can go negative);
        scope = SlingFilterScope.REQUEST)
@Properties({
        @Property(
                label = "Vendor",
                name = "service.vendor",
                value = "SampleVendor",
                propertyPrivate = true
        )
})
public class AssetFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request;
        final SlingHttpServletResponse slingResponse = (SlingHttpServletResponse) response;
        slingResponse.setHeader("myheader1","no-cache");
        slingResponse.setHeader("myheader2","no-store");
        chain.doFilter(request, response);
    }

    @Override
    public void destroy() {

    }
}
</code></pre>

<hr>

<p>Just a update, initialy I thought the problem only happens to .pdf file, but this also happens to image file. So I created a regular JSP web application, and this code is working for regular web app.  Is there something funny on AEM side?</p>