替换部分过期netty方法

master
星期八 5 years ago
parent 7e94538ffd
commit a6d8dd0860
  1. 34
      proxy-server/src/main/java/org/fengfei/lanproxy/server/config/web/HttpRequestHandler.java

@ -5,6 +5,7 @@ import java.io.RandomAccessFile;
import java.net.URI;
import java.nio.charset.Charset;
import io.netty.handler.codec.http.*;
import org.fengfei.lanproxy.common.JsonUtil;
import io.netty.buffer.Unpooled;
@ -13,17 +14,6 @@ import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.DefaultFileRegion;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.DefaultHttpResponse;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpHeaders.Names;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpVersion;
import io.netty.handler.codec.http.LastHttpContent;
import io.netty.handler.ssl.SslHandler;
import io.netty.handler.stream.ChunkedNioFile;
@ -60,11 +50,11 @@ public class HttpRequestHandler extends SimpleChannelInboundHandler<FullHttpRequ
FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.valueOf(code),
Unpooled.wrappedBuffer(content.getBytes(Charset.forName("UTF-8"))));
response.headers().set(Names.CONTENT_TYPE, mimeType);
response.headers().set(Names.CONTENT_LENGTH, response.content().readableBytes());
response.headers().set(Names.SERVER, SERVER_VS);
response.headers().set(HttpHeaderNames.CONTENT_TYPE, mimeType);
response.headers().set(HttpHeaderNames.CONTENT_LENGTH, response.content().readableBytes());
response.headers().set(HttpHeaderNames.SERVER, SERVER_VS);
ChannelFuture future = ctx.writeAndFlush(response);
if (!HttpHeaders.isKeepAlive(request)) {
if (!HttpUtil.isKeepAlive(request)) {
future.addListener(ChannelFutureListener.CLOSE);
}
@ -79,7 +69,7 @@ public class HttpRequestHandler extends SimpleChannelInboundHandler<FullHttpRequ
*/
private void outputPages(ChannelHandlerContext ctx, FullHttpRequest request) throws Exception {
HttpResponseStatus status = HttpResponseStatus.OK;
URI uri = new URI(request.getUri());
URI uri = new URI(request.uri());
String uriPath = uri.getPath();
uriPath = HTTP_SYMBOL.equals(uriPath)? "/index.html" : uriPath;
String path = PAGE_FOLDER + uriPath;
@ -95,7 +85,7 @@ public class HttpRequestHandler extends SimpleChannelInboundHandler<FullHttpRequ
return;
}
if (HttpHeaders.is100ContinueExpected(request)) {
if (HttpUtil.is100ContinueExpected(request)) {
send100Continue(ctx);
}
@ -111,15 +101,15 @@ public class HttpRequestHandler extends SimpleChannelInboundHandler<FullHttpRequ
}
}
HttpResponse response = new DefaultHttpResponse(request.getProtocolVersion(), status);
response.headers().set(HttpHeaders.Names.CONTENT_TYPE, mimeType);
HttpResponse response = new DefaultHttpResponse(request.protocolVersion(), status);
response.headers().set(HttpHeaderNames.CONTENT_TYPE, mimeType);
boolean keepAlive = HttpHeaders.isKeepAlive(request);
if (keepAlive) {
response.headers().set(HttpHeaders.Names.CONTENT_LENGTH, length);
response.headers().set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
response.headers().set(HttpHeaderNames.CONTENT_LENGTH, length);
response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
}
response.headers().set(Names.SERVER, SERVER_VS);
response.headers().set(HttpHeaderNames.SERVER, SERVER_VS);
ctx.write(response);
if (ctx.pipeline().get(SslHandler.class) == null) {

Loading…
Cancel
Save