diff --git a/proxy/src/main/java/net/md_5/bungee/http/HttpHandler.java b/proxy/src/main/java/net/md_5/bungee/http/HttpHandler.java index a1e59b47a..aa21c990f 100644 --- a/proxy/src/main/java/net/md_5/bungee/http/HttpHandler.java +++ b/proxy/src/main/java/net/md_5/bungee/http/HttpHandler.java @@ -7,7 +7,7 @@ import io.netty.handler.codec.http.HttpObject; import io.netty.handler.codec.http.HttpResponse; import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.handler.codec.http.LastHttpContent; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import lombok.RequiredArgsConstructor; import net.md_5.bungee.api.Callback; @@ -16,7 +16,7 @@ public class HttpHandler extends SimpleChannelInboundHandler { private final Callback callback; - private final StringBuilder buffer = new StringBuilder(); + private StringBuilder buffer; @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception @@ -41,6 +41,7 @@ public class HttpHandler extends SimpleChannelInboundHandler if ( responseCode == HttpResponseStatus.NO_CONTENT.code() ) { + buffer = new StringBuilder( 0 ); done( ctx ); return; } @@ -49,11 +50,13 @@ public class HttpHandler extends SimpleChannelInboundHandler { throw new IllegalStateException( "Expected HTTP response 200 OK, got " + response.status() ); } + + buffer = new StringBuilder( response.headers().contains( "Content-Length" ) ? Integer.parseInt( response.headers().get( "Content-Length" ) ) : 0x600 ); } if ( msg instanceof HttpContent ) { HttpContent content = (HttpContent) msg; - buffer.append( content.content().toString( Charset.forName( "UTF-8" ) ) ); + buffer.append( content.content().toString( StandardCharsets.UTF_8 ) ); if ( msg instanceof LastHttpContent ) {