public int requestMap(Request req) {
// if( debug>0 ) log("Req map " + req);
if( req.getHandler() != null )
return 0;
Context ctx=req.getContext();
// will call getRealPath(), all path normalization
// and a number of checks
String pathInfo=req.servletPath().toString();
if( pathInfo==null ) pathInfo="";
if( debug > 0 ) log("Method: " + req.method());
if(req.method().equalsIgnoreCase("OPTIONS") ||
req.method().equalsIgnoreCase("TRACE")) {
req.setHandler( ctx.getServletByName( "tomcat.fileHandler"));
return 0;
}
String absPath=FileUtil.safePath( ctx.getAbsolutePath(),
pathInfo);
if( debug > 0 ) log( "RequestMap " + req + " " + absPath + " " +
ctx.getAbsolutePath() );
if( absPath == null ) return 0;
String requestURI=req.requestURI().toString();
if( debug > 0 )
log( "Requested: " + absPath );
File file=new File( absPath );
if( file.isFile() ) {
if( debug > 0 ) log( "Setting handler to file " + absPath);
req.setNote( realFileNote, absPath );
req.setHandler( ctx.getServletByName( "tomcat.fileHandler"));
return 0;
}
if( ! file.isDirectory() ) {
// we support only files and dirs
if( debug > 0) log( "No file and no directory");
return 0; // no handler is set - will end up as 404
}
// consistent with Apache
if( ! requestURI.endsWith("/") && !req.getResponse().isIncluded()) {
String redirectURI= requestURI + "/";
redirectURI=fixURLRewriting( req, redirectURI );
String query = req.query().toString();
if( query != null && !query.equals("") )
redirectURI += "?" + query;
req.setAttribute("javax.servlet.error.message",
redirectURI);
if( debug > 0) log( "Redirect " + redirectURI );
req.setHandler( ctx.getServletByName( "tomcat.redirectHandler"));
return 0;
}
// Directory, check if we have a welcome file
String welcomeFile = null;
if( strict23Welcome ) {
welcomeFile = getStrictWelcomeFile(ctx, file, pathInfo);
} else {
welcomeFile = getWelcomeFile(ctx, file);
}
if( debug > 0 )
log( "DefaultServlet: welcome file: " + welcomeFile);
// Doesn't matter if we are or not in include
if( welcomeFile == null ) {
// normal dir, no welcome.
req.setHandler( ctx.getServletByName( "tomcat.dirHandler"));
if( debug > 0) log( "Dir handler");
return 0;
}
int status = 0;
if(useInternal) {