feat: channelRead0 处理逻辑移动到业务线程
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
93c83cac94
commit
d9e2b50953
@ -159,6 +159,7 @@ const WebSocketServerProtocolHandler = Java.type('io.netty.handler.codec.http.we
|
|||||||
const SimpleChannelInboundHandler = Java.type('io.netty.channel.SimpleChannelInboundHandler')
|
const SimpleChannelInboundHandler = Java.type('io.netty.channel.SimpleChannelInboundHandler')
|
||||||
const FullHttpRequestMatcher = TypeParameterMatcher.get(base.getClass('io.netty.handler.codec.http.FullHttpRequest'))
|
const FullHttpRequestMatcher = TypeParameterMatcher.get(base.getClass('io.netty.handler.codec.http.FullHttpRequest'))
|
||||||
const File = Java.type('java.io.File')
|
const File = Java.type('java.io.File')
|
||||||
|
const Runnable = Java.type('java.lang.Runnable')
|
||||||
const RandomAccessFile = Java.type('java.io.RandomAccessFile')
|
const RandomAccessFile = Java.type('java.io.RandomAccessFile')
|
||||||
const DefaultFileRegion = Java.type('io.netty.channel.DefaultFileRegion')
|
const DefaultFileRegion = Java.type('io.netty.channel.DefaultFileRegion')
|
||||||
const ChannelFutureListener = Java.type('io.netty.channel.ChannelFutureListener')
|
const ChannelFutureListener = Java.type('io.netty.channel.ChannelFutureListener')
|
||||||
@ -170,30 +171,34 @@ const HttpRequestHandler = Java.extend(SimpleChannelInboundHandler, {
|
|||||||
if ('/ws' == request.getUri()) {
|
if ('/ws' == request.getUri()) {
|
||||||
ctx.fireChannelRead(request.retain())
|
ctx.fireChannelRead(request.retain())
|
||||||
} else {
|
} else {
|
||||||
if (HttpHeaders.is100ContinueExpected(request)) {
|
ctx.executor().execute(new Runnable({
|
||||||
ctx.writeAndFlush(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE))
|
run: () => {
|
||||||
}
|
if (HttpHeaders.is100ContinueExpected(request)) {
|
||||||
let filename = request.getUri().split('?')[0].substr(1)
|
ctx.writeAndFlush(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE))
|
||||||
let file = new File('/home/project/TSWorkSpace/ms/packages/plugins/public', filename || 'index.html')
|
}
|
||||||
if (!file.exists() || !file.isFile()) {
|
let filename = request.getUri().split('?')[0].substr(1)
|
||||||
ctx.write(new DefaultHttpResponse(request.getProtocolVersion(), HttpResponseStatus.NOT_FOUND))
|
let file = new File('/home/project/WebWorkSpace/MiaoConsole', filename || 'index.html')
|
||||||
ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT).addListener(ChannelFutureListener.CLOSE)
|
if (!file.exists() || !file.isFile()) {
|
||||||
return
|
ctx.write(new DefaultHttpResponse(request.getProtocolVersion(), HttpResponseStatus.NOT_FOUND))
|
||||||
}
|
ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT).addListener(ChannelFutureListener.CLOSE)
|
||||||
let response = new DefaultHttpResponse(request.getProtocolVersion(), HttpResponseStatus.OK)
|
return
|
||||||
response.headers().set(HttpHeaders.Names.CONTENT_TYPE, "text/html charset=UTF-8")
|
}
|
||||||
let raf = new RandomAccessFile(file, 'r')
|
let response = new DefaultHttpResponse(request.getProtocolVersion(), HttpResponseStatus.OK)
|
||||||
let keepAlive = HttpHeaders.isKeepAlive(request)
|
response.headers().set(HttpHeaders.Names.CONTENT_TYPE, "text/html charset=UTF-8")
|
||||||
if (keepAlive) {
|
let raf = new RandomAccessFile(file, 'r')
|
||||||
response.headers().set(HttpHeaders.Names.CONTENT_LENGTH, file.length())
|
let keepAlive = HttpHeaders.isKeepAlive(request)
|
||||||
response.headers().set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.KEEP_ALIVE)
|
if (keepAlive) {
|
||||||
}
|
response.headers().set(HttpHeaders.Names.CONTENT_LENGTH, file.length())
|
||||||
ctx.write(response)
|
response.headers().set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.KEEP_ALIVE)
|
||||||
ctx.write(new DefaultFileRegion(raf.getChannel(), 0, raf.length()))
|
}
|
||||||
let future = ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT)
|
ctx.write(response)
|
||||||
if (!keepAlive) {
|
ctx.write(new DefaultFileRegion(raf.getChannel(), 0, raf.length()))
|
||||||
future.addListener(ChannelFutureListener.CLOSE)
|
let future = ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT)
|
||||||
}
|
if (!keepAlive) {
|
||||||
|
future.addListener(ChannelFutureListener.CLOSE)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user