Set Content-Type header when forwarding to a local resource.

This commit is contained in:
hns 2004-02-13 20:51:02 +00:00
parent 5cf2dbc927
commit 2ec37bda9c

View file

@ -301,7 +301,7 @@ public abstract class AbstractServletClient extends HttpServlet {
void writeResponse(HttpServletRequest req, HttpServletResponse res, void writeResponse(HttpServletRequest req, HttpServletResponse res,
ResponseTrans hopres) throws IOException { ResponseTrans hopres) throws IOException {
if (hopres.getForward() != null) { if (hopres.getForward() != null) {
sendForward(res, hopres.getForward()); sendForward(res, hopres);
return; return;
} }
@ -428,8 +428,9 @@ public abstract class AbstractServletClient extends HttpServlet {
* Forward the request to a static file. The file must be reachable via * Forward the request to a static file. The file must be reachable via
* the context's protectedStatic resource base. * the context's protectedStatic resource base.
*/ */
void sendForward(ServletResponse res, String forward) throws IOException { void sendForward(HttpServletResponse res, ResponseTrans hopres) throws IOException {
String forward = hopres.getForward();
ServletContext cx = getServletConfig().getServletContext(); ServletContext cx = getServletConfig().getServletContext();
String path = cx.getRealPath(forward); String path = cx.getRealPath(forward);
if (path == null) if (path == null)
@ -438,6 +439,8 @@ public abstract class AbstractServletClient extends HttpServlet {
File file = new File(path); File file = new File(path);
int length = (int) file.length(); int length = (int) file.length();
res.setContentLength(length); res.setContentLength(length);
res.setContentType(hopres.getContentType());
InputStream in = cx.getResourceAsStream(forward); InputStream in = cx.getResourceAsStream(forward);
if (in == null) if (in == null)
throw new IOException("Can't read "+path); throw new IOException("Can't read "+path);