Remove unnecessary this. (#11035)

Motivation:
There are unnecessary `this` keyword usages in `HttpStaticFileServerHandler`.

Modification:
Removed unnecessary `this` keywords.

Result:
Clean code
This commit is contained in:
Aayush Atharva 2021-02-26 16:43:10 +05:30 committed by GitHub
parent dde82f62f0
commit edf44732de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -121,7 +121,7 @@ public class HttpStaticFileServerHandler extends SimpleChannelInboundHandler<Ful
} }
if (!GET.equals(request.method())) { if (!GET.equals(request.method())) {
this.sendError(ctx, METHOD_NOT_ALLOWED); sendError(ctx, METHOD_NOT_ALLOWED);
return; return;
} }
@ -129,21 +129,21 @@ public class HttpStaticFileServerHandler extends SimpleChannelInboundHandler<Ful
final String uri = request.uri(); final String uri = request.uri();
final String path = sanitizeUri(uri); final String path = sanitizeUri(uri);
if (path == null) { if (path == null) {
this.sendError(ctx, FORBIDDEN); sendError(ctx, FORBIDDEN);
return; return;
} }
File file = new File(path); File file = new File(path);
if (file.isHidden() || !file.exists()) { if (file.isHidden() || !file.exists()) {
this.sendError(ctx, NOT_FOUND); sendError(ctx, NOT_FOUND);
return; return;
} }
if (file.isDirectory()) { if (file.isDirectory()) {
if (uri.endsWith("/")) { if (uri.endsWith("/")) {
this.sendListing(ctx, file, uri); sendListing(ctx, file, uri);
} else { } else {
this.sendRedirect(ctx, uri + '/'); sendRedirect(ctx, uri + '/');
} }
return; return;
} }
@ -164,7 +164,7 @@ public class HttpStaticFileServerHandler extends SimpleChannelInboundHandler<Ful
long ifModifiedSinceDateSeconds = ifModifiedSinceDate.getTime() / 1000; long ifModifiedSinceDateSeconds = ifModifiedSinceDate.getTime() / 1000;
long fileLastModifiedSeconds = file.lastModified() / 1000; long fileLastModifiedSeconds = file.lastModified() / 1000;
if (ifModifiedSinceDateSeconds == fileLastModifiedSeconds) { if (ifModifiedSinceDateSeconds == fileLastModifiedSeconds) {
this.sendNotModified(ctx); sendNotModified(ctx);
return; return;
} }
} }
@ -259,9 +259,9 @@ public class HttpStaticFileServerHandler extends SimpleChannelInboundHandler<Ful
// Simplistic dumb security check. // Simplistic dumb security check.
// You will have to do something serious in the production environment. // You will have to do something serious in the production environment.
if (uri.contains(File.separator + '.') || if (uri.contains(File.separator + '.') ||
uri.contains('.' + File.separator) || uri.contains('.' + File.separator) ||
uri.charAt(0) == '.' || uri.charAt(uri.length() - 1) == '.' || uri.charAt(0) == '.' || uri.charAt(uri.length() - 1) == '.' ||
INSECURE_URI.matcher(uri).matches()) { INSECURE_URI.matcher(uri).matches()) {
return null; return null;
} }
@ -273,18 +273,18 @@ public class HttpStaticFileServerHandler extends SimpleChannelInboundHandler<Ful
private void sendListing(ChannelHandlerContext ctx, File dir, String dirPath) { private void sendListing(ChannelHandlerContext ctx, File dir, String dirPath) {
StringBuilder buf = new StringBuilder() StringBuilder buf = new StringBuilder()
.append("<!DOCTYPE html>\r\n") .append("<!DOCTYPE html>\r\n")
.append("<html><head><meta charset='utf-8' /><title>") .append("<html><head><meta charset='utf-8' /><title>")
.append("Listing of: ") .append("Listing of: ")
.append(dirPath) .append(dirPath)
.append("</title></head><body>\r\n") .append("</title></head><body>\r\n")
.append("<h3>Listing of: ") .append("<h3>Listing of: ")
.append(dirPath) .append(dirPath)
.append("</h3>\r\n") .append("</h3>\r\n")
.append("<ul>") .append("<ul>")
.append("<li><a href=\"../\">..</a></li>\r\n"); .append("<li><a href=\"../\">..</a></li>\r\n");
File[] files = dir.listFiles(); File[] files = dir.listFiles();
if (files != null) { if (files != null) {
@ -299,10 +299,10 @@ public class HttpStaticFileServerHandler extends SimpleChannelInboundHandler<Ful
} }
buf.append("<li><a href=\"") buf.append("<li><a href=\"")
.append(name) .append(name)
.append("\">") .append("\">")
.append(name) .append(name)
.append("</a></li>\r\n"); .append("</a></li>\r\n");
} }
} }
@ -314,14 +314,14 @@ public class HttpStaticFileServerHandler extends SimpleChannelInboundHandler<Ful
FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, buffer); FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, buffer);
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/html; charset=UTF-8"); response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/html; charset=UTF-8");
this.sendAndCleanupConnection(ctx, response); sendAndCleanupConnection(ctx, response);
} }
private void sendRedirect(ChannelHandlerContext ctx, String newUri) { private void sendRedirect(ChannelHandlerContext ctx, String newUri) {
FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, FOUND, Unpooled.EMPTY_BUFFER); FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, FOUND, Unpooled.EMPTY_BUFFER);
response.headers().set(HttpHeaderNames.LOCATION, newUri); response.headers().set(HttpHeaderNames.LOCATION, newUri);
this.sendAndCleanupConnection(ctx, response); sendAndCleanupConnection(ctx, response);
} }
private void sendError(ChannelHandlerContext ctx, HttpResponseStatus status) { private void sendError(ChannelHandlerContext ctx, HttpResponseStatus status) {
@ -329,7 +329,7 @@ public class HttpStaticFileServerHandler extends SimpleChannelInboundHandler<Ful
HTTP_1_1, status, Unpooled.copiedBuffer("Failure: " + status + "\r\n", CharsetUtil.UTF_8)); HTTP_1_1, status, Unpooled.copiedBuffer("Failure: " + status + "\r\n", CharsetUtil.UTF_8));
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain; charset=UTF-8"); response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain; charset=UTF-8");
this.sendAndCleanupConnection(ctx, response); sendAndCleanupConnection(ctx, response);
} }
/** /**
@ -342,7 +342,7 @@ public class HttpStaticFileServerHandler extends SimpleChannelInboundHandler<Ful
FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, NOT_MODIFIED, Unpooled.EMPTY_BUFFER); FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, NOT_MODIFIED, Unpooled.EMPTY_BUFFER);
setDateHeader(response); setDateHeader(response);
this.sendAndCleanupConnection(ctx, response); sendAndCleanupConnection(ctx, response);
} }
/** /**