in core/src/main/java/com/taobao/arthas/core/shell/term/impl/http/HttpRequestHandler.java [53:110]
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) throws Exception {
String path = new URI(request.uri()).getPath();
if (wsUri.equalsIgnoreCase(path)) {
ctx.fireChannelRead(request.retain());
} else {
if (HttpUtil.is100ContinueExpected(request)) {
send100Continue(ctx);
}
HttpResponse response = null;
if ("/".equals(path)) {
path = "/index.html";
}
boolean isFileResponseFinished = false;
try {
//handle http restful api
if ("/api".equals(path)) {
response = httpApiHandler.handle(ctx, request);
}
//handle webui requests
if (path.equals("/ui")) {
response = createRedirectResponse(request, "/ui/");
}
if (path.equals("/ui/")) {
path += "index.html";
}
//try classpath resource first
if (response == null) {
response = readFileFromResource(request, path);
}
//try output dir later, avoid overlay classpath resources files
if (response == null) {
response = DirectoryBrowser.directView(dir, path, request, ctx);
isFileResponseFinished = response != null;
}
//not found
if (response == null) {
response = createResponse(request, HttpResponseStatus.NOT_FOUND, "Not found");
}
} catch (Throwable e) {
logger.error("arthas process http request error: " + request.uri(), e);
} finally {
//If it is null, an error may occur
if (response == null) {
response = createResponse(request, HttpResponseStatus.INTERNAL_SERVER_ERROR, "Server error");
}
if (!isFileResponseFinished) {
ChannelFuture future = writeResponse(ctx, response);
future.addListener(ChannelFutureListener.CLOSE);
}
}
}
}