private void handleHttpRequest(ChannelHandlerContext ctx, MessageEvent e)
			throws IOException {
		HttpRequest req = (HttpRequest) e.getMessage();
		// Allow only GET methods.
		if (req.getMethod() != GET) {
			sendHttpResponse(ctx, req, new DefaultHttpResponse(HTTP_1_1,
					FORBIDDEN));
			return;
		}
		String uri = req.getUri();

		if (uri.indexOf("/migapi") == 0) {
			handleApi(uri.substring(7), ctx, req);
		} else if (uri.indexOf("/appdir") == 0) {
			logger.info("appdir:" + uri);
			HttpResponse res = new DefaultHttpResponse(HTTP_1_1, OK);

			ColdMigServerDirectoryPage dirpage = new ColdMigServerDirectoryPage();
			ChannelBuffer content = dirpage.getContent(uri.substring(8));

			res.setHeader(CONTENT_TYPE, "text/html; charset=UTF-8");
			res.setHeader("UPTYPE", "dir");
			res.setHeader("UPNAME", "app");
			setContentLength(res, content.readableBytes());

			res.setContent(content);
			sendHttpResponse(ctx, req, res);
			return;
		} else if (uri.equals("/favicon.ico")) {
			HttpResponse res = new DefaultHttpResponse(HTTP_1_1, NOT_FOUND);
			sendHttpResponse(ctx, req, res);
			return;
		} else if (uri.equals("/")) {
			HttpResponse res = new DefaultHttpResponse(HTTP_1_1, NOT_FOUND);
			sendHttpResponse(ctx, req, res);
			return;
		} else {
			String path = sanitizeUri(uri);
			File file = new File(path);
			if (!file.exists()) {
				HttpResponse res = new DefaultHttpResponse(HTTP_1_1, NOT_FOUND);
				sendHttpResponse(ctx, req, res);
				return;
			}
			// request lastmodified time
			String cache_ctrl = req.getHeader(Names.CACHE_CONTROL);
			if (cache_ctrl != null) {
				Long reqlm = Long.parseLong(cache_ctrl) / 1000;

				// file lastmodified time
				Long filelm = file.lastModified() / 1000;

				// only compare up to the second
				if (!reqlm.equals(filelm)) {
					logger.info(file.getName() + ":" + reqlm + "  " + filelm);
					sendFile(ctx, e, file);
				} else {
					logger.info(file.getName() + " is not modified!");
					// sendFile(ctx, e, file);
					sendNotModified(ctx);
				}
			} else {
				logger.info(file.getName());
				sendFile(ctx, e, file);
			}
		}
	}