mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-22 16:41:46 +03:00
FileServerHandler использование
This commit is contained in:
parent
111ebd2f19
commit
fb7ac48962
3 changed files with 3 additions and 44 deletions
|
@ -28,7 +28,7 @@ public void invoke(String... args) throws Exception {
|
|||
if (handler == null)
|
||||
handler = new NettyServerSocketHandler(server);
|
||||
if (args[0].equals("start")) {
|
||||
CommonHelper.newThread("Netty Server",true,handler);
|
||||
CommonHelper.newThread("Netty Server",true,handler).start();
|
||||
}
|
||||
if (args[0].equals("stop")) {
|
||||
handler.close();
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
package ru.gravit.launchserver.fileserver;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.handler.codec.http.HttpObjectAggregator;
|
||||
import io.netty.handler.codec.http.HttpServerCodec;
|
||||
import io.netty.handler.ssl.SslContext;
|
||||
import io.netty.handler.stream.ChunkedWriteHandler;
|
||||
|
||||
public class FileInitializer extends ChannelInitializer<SocketChannel> {
|
||||
|
||||
private final SslContext sslCtx;
|
||||
private final File base;
|
||||
private final boolean outDirs;
|
||||
|
||||
public FileInitializer(SslContext sslCtx, File base, boolean outDirs) {
|
||||
this.sslCtx = sslCtx;
|
||||
this.base = base;
|
||||
this.outDirs = outDirs;
|
||||
}
|
||||
|
||||
public FileInitializer(File base, boolean outDirs) {
|
||||
this.sslCtx = null;
|
||||
this.base = base;
|
||||
this.outDirs = outDirs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initChannel(SocketChannel ch) {
|
||||
ChannelPipeline pipeline = ch.pipeline();
|
||||
if (sslCtx != null) {
|
||||
pipeline.addLast(sslCtx.newHandler(ch.alloc()));
|
||||
}
|
||||
pipeline.addLast(new HttpServerCodec());
|
||||
pipeline.addLast(new HttpObjectAggregator(65536));
|
||||
pipeline.addLast(new ChunkedWriteHandler());
|
||||
pipeline.addLast(new FileServerHandler(base, outDirs));
|
||||
}
|
||||
}
|
|
@ -19,6 +19,7 @@
|
|||
import ru.gravit.launcher.ssl.LauncherKeyStore;
|
||||
import ru.gravit.launcher.ssl.LauncherTrustManager;
|
||||
import ru.gravit.launchserver.LaunchServer;
|
||||
import ru.gravit.launchserver.fileserver.FileServerHandler;
|
||||
import ru.gravit.launchserver.response.Response;
|
||||
import ru.gravit.launchserver.socket.websocket.WebSocketFrameHandler;
|
||||
import ru.gravit.launchserver.socket.websocket.WebSocketIndexPageHandler;
|
||||
|
@ -142,7 +143,7 @@ public void initChannel(NioSocketChannel ch) {
|
|||
pipeline.addLast(new HttpObjectAggregator(65536));
|
||||
pipeline.addLast(new WebSocketServerCompressionHandler());
|
||||
pipeline.addLast(new WebSocketServerProtocolHandler(WEBSOCKET_PATH, null, true));
|
||||
pipeline.addLast(new WebSocketIndexPageHandler(WEBSOCKET_PATH));
|
||||
pipeline.addLast(new FileServerHandler(LaunchServer.server.updatesDir,true));
|
||||
pipeline.addLast(new WebSocketFrameHandler());
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue