2014-09-20 6:32 GMT+04:00 John Polansky <johnpolan...@gmail.com>:
> System:
> Tomcat 5.5.15 Java 1.5 Solaris/SPARC

Something old, with known issues and unsupported....

> Guys, new to the group, well new to tomcat completely I was hoping to get a
> solution for our issue. We have a piece of software that is no longer
> supported and I'm trying to fix an issue. The issue that when this software
> generates .PNG files it labels them "image1." without an extension. The
> problem we are having is I think there is some sort of safeguard in Tomcat
> that sets all extension-less files to be "text/html" content-type. This is
> a problem for us and I was trying to use a java tomcat filter to fix this.
> I've successfully built the filter here is the cut down version.
>
> public class ImageExtFix implements Filter {
>
>     public void doFilter(ServletRequest req, ServletResponse res,
>             FilterChain chain) throws IOException, ServletException {
>
>         HttpServletRequest request = (HttpServletRequest) req;
>         HttpServletResponse response = (HttpServletResponse) res;
>         response.addHeader("JunkHeader", "WOOT");
>         response.addHeader("Content-Type", "image/png");

Just use "response.setContentType()"

http://docs.oracle.com/javaee/1.4/api/javax/servlet/ServletResponse.html#setContentType%28java.lang.String%29

The method is NOOP if either HTTP headers have already been sent to
client (aka isCommitted()) or it is an "included" dispatch.

Trying to send multiple Content-Type headers (via addHeader()) is no good.

>         chain.doFilter(req, res);
>     }
>
> The filter is working perfectly I can tell this because I can see my
> "JunkHeader" showing up on the files. However I have tried "addHeader" and
> "setHeader" but no matter what the Content-Type is still be forced to
> "index.html"
>
> I did some testing and I found that if I rename the "image1." file to
> "image1.tx" which is an extension that tomcat doesn't have a MIME type for,
> then my Filter correctly modifies this file and it gets set to "image/png"

What web browser are you using?

Use some software to get actual HTTP headers of a response.

> So at this point I think that there must be some sort of safe guard build
> into tomcat to prevent you from changing the content type of files with
> extensions tomcat recognizes, perhaps to prevent malicious code.
>
> Can anyone suggest an alternative to this, I've been scouring the web
> without much luck. I'd appreciate any suggestions keep in mind I'm pretty
> new tomcat/java as well so please give me keywords I can Google I would
> appreciate it.
>
> Thanks!
>
> John

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to