mirror of
https://gitee.com/BDWare/front-base
synced 2025-01-10 09:54:00 +00:00
optimize: use jquery 2.1.4.min
refactor: DOA Contract update: use doip sdk 1.0.2 optimize build.gradle
This commit is contained in:
parent
05a8a992db
commit
826b256c85
@ -23,10 +23,7 @@ sourceSets {
|
|||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
api project (":common")
|
api project (":common")
|
||||||
api 'io.netty:netty-all:4.1.52.Final'
|
|
||||||
api 'io.netty:netty-tcnative-boringssl-static:2.0.41.Final'
|
api 'io.netty:netty-tcnative-boringssl-static:2.0.41.Final'
|
||||||
api 'org.apache.logging.log4j:log4j-core:2.15.0'
|
|
||||||
api 'org.apache.logging.log4j:log4j-api:2.15.0'
|
|
||||||
api 'com.google.code.gson:gson:2.8.8'
|
api 'com.google.code.gson:gson:2.8.8'
|
||||||
|
|
||||||
testImplementation 'junit:junit:4.13.2'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
|
@ -67,7 +67,6 @@ public class HttpResultCallback extends ResultCallback implements Runnable {
|
|||||||
HttpUtil.setContentLength(response, bytes.length);
|
HttpUtil.setContentLength(response, bytes.length);
|
||||||
ChannelFuture future = ctxField.writeAndFlush(response);
|
ChannelFuture future = ctxField.writeAndFlush(response);
|
||||||
future.addListener(ChannelFutureListener.CLOSE);
|
future.addListener(ChannelFutureListener.CLOSE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDecodeBase64() {
|
public void setDecodeBase64() {
|
||||||
|
@ -11,18 +11,13 @@ import io.netty.handler.stream.ChunkedFile;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileFilter;
|
import java.io.FileFilter;
|
||||||
import java.io.RandomAccessFile;
|
import java.io.RandomAccessFile;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.URLDecoder;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
|
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
|
||||||
|
|
||||||
public class HttpFileHandleAdapter extends SimpleChannelInboundHandler<FullHttpRequest> {
|
public class HttpFileHandleAdapter extends SimpleChannelInboundHandler<FullHttpRequest> {
|
||||||
private static final Pattern ALLOWED_FILE_NAME =
|
|
||||||
Pattern.compile("[A-Za-z0-9][-_A-Za-z0-9\\.]*");
|
|
||||||
private static final Pattern INSECURE_URI = Pattern.compile(".*[<>&\"].*");
|
|
||||||
FileFilter fileFilter;
|
FileFilter fileFilter;
|
||||||
private String location;
|
private final String location;
|
||||||
|
|
||||||
public HttpFileHandleAdapter(String path, FileFilter fileFilter) {
|
public HttpFileHandleAdapter(String path, FileFilter fileFilter) {
|
||||||
location = path;
|
location = path;
|
||||||
@ -35,7 +30,7 @@ public class HttpFileHandleAdapter extends SimpleChannelInboundHandler<FullHttpR
|
|||||||
HTTP_1_1,
|
HTTP_1_1,
|
||||||
status,
|
status,
|
||||||
Unpooled.wrappedBuffer(
|
Unpooled.wrappedBuffer(
|
||||||
("Failure: " + status.toString() + "\r\n").getBytes()));
|
("Failure: " + status + "\r\n").getBytes()));
|
||||||
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain; charset=UTF-8");
|
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain; charset=UTF-8");
|
||||||
ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
|
ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
|
||||||
}
|
}
|
||||||
@ -60,36 +55,6 @@ public class HttpFileHandleAdapter extends SimpleChannelInboundHandler<FullHttpR
|
|||||||
ctx.writeAndFlush(response);
|
ctx.writeAndFlush(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String sanitizeUri(String uri) {
|
|
||||||
try {
|
|
||||||
// 使用JDK的URLDecoder进行解码
|
|
||||||
uri = URLDecoder.decode(uri, "UTF-8");
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
try {
|
|
||||||
uri = URLDecoder.decode(uri, "ISO-8859-1");
|
|
||||||
} catch (UnsupportedEncodingException e1) {
|
|
||||||
throw new Error();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!uri.startsWith("/")) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (uri.contains("..")) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
// 将硬编码的文件路径
|
|
||||||
uri = uri.replace('/', File.separatorChar);
|
|
||||||
if (uri.contains(File.separator + '.')
|
|
||||||
|| uri.contains('.' + File.separator)
|
|
||||||
|| uri.startsWith(".")
|
|
||||||
|| uri.endsWith(".")
|
|
||||||
|| INSECURE_URI.matcher(uri).matches()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return System.getProperty("user.dir") + File.separator + uri;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request)
|
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
@ -137,9 +102,8 @@ public class HttpFileHandleAdapter extends SimpleChannelInboundHandler<FullHttpR
|
|||||||
HttpUtil.setKeepAlive(response, true);
|
HttpUtil.setKeepAlive(response, true);
|
||||||
}
|
}
|
||||||
ctx.write(response);
|
ctx.write(response);
|
||||||
// 同过netty的村可多File对象直接将文件写入到发送缓冲区,最后为sendFileFeature增加GenericFeatureListener,
|
// File对象直接将文件写入到发送缓冲区,最后为sendFileFeature增加GenericFeatureListener,
|
||||||
// 如果发送完成,打印“Transfer complete”
|
ctx.write(new ChunkedFile(file, 0, file.length(), 512 * 1024));
|
||||||
ctx.write(new ChunkedFile(file, 0, file.length(), 512 * 1024), ctx.newPromise());
|
|
||||||
// 写入文件尾部
|
// 写入文件尾部
|
||||||
ChannelFuture future = ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT);
|
ChannelFuture future = ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT);
|
||||||
if (!keepAlive) {
|
if (!keepAlive) {
|
||||||
|
Loading…
Reference in New Issue
Block a user