fix(mainhttp): send 404 at end of pipeline
This should allow other handlers that accept HTTP to also get their chance
This commit is contained in:
parent
0c22ba6356
commit
6bb91ddba0
@ -41,9 +41,16 @@ public class HttpDecoder extends ChannelInboundHandlerAdapter {
|
||||
buf.readBytes(data);
|
||||
buf.release();
|
||||
// Process request
|
||||
byte[] response = MainHttp.handle(data);
|
||||
if (response == null) {
|
||||
// We don't handle this request, maybe some other mod does
|
||||
passOn = true;
|
||||
ctx.channel().pipeline().addLast("libjf_http_404", new NotFoundAdapter());
|
||||
return;
|
||||
}
|
||||
ctx.pipeline()
|
||||
.firstContext()
|
||||
.writeAndFlush(Unpooled.wrappedBuffer(MainHttp.handle(data)))
|
||||
.writeAndFlush(Unpooled.wrappedBuffer(response))
|
||||
.addListener(ChannelFutureListener.CLOSE);
|
||||
} catch (RuntimeException re) {
|
||||
MainHttp.LOGGER.error("Could not process HTTP", re);
|
||||
@ -55,4 +62,15 @@ public class HttpDecoder extends ChannelInboundHandlerAdapter {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class NotFoundAdapter extends ChannelInboundHandlerAdapter {
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||
// We didn't handle this request, and neither did any other mod
|
||||
ctx.pipeline()
|
||||
.firstContext()
|
||||
.writeAndFlush(Unpooled.wrappedBuffer(MainHttp.NOT_FOUND))
|
||||
.addListener(ChannelFutureListener.CLOSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ public class MainHttp {
|
||||
.stream()
|
||||
.filter(MainHttpHandler::isActive)
|
||||
.toList();
|
||||
private static final byte[] NOT_FOUND = """
|
||||
public static final byte[] NOT_FOUND = """
|
||||
HTTP/1.1 404 Not Found
|
||||
Connection: keep-alive
|
||||
Content-Length: 0
|
||||
|
@ -11,6 +11,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
public class ServerNetworkIo$1Mixin {
|
||||
@Inject(method = "initChannel(Lio/netty/channel/Channel;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/ClientConnection;addHandlers(Lio/netty/channel/ChannelPipeline;Lnet/minecraft/network/NetworkSide;ZLnet/minecraft/network/handler/PacketSizeLogger;)V"))
|
||||
private void inject(Channel channel, CallbackInfo ci) {
|
||||
channel.pipeline().addAfter("legacy_query", "libjf_http", new HttpDecoder());
|
||||
// directly after legacy_query
|
||||
channel.pipeline().addLast("libjf_http", new HttpDecoder());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user