1.新增注视 2.修改部分可能会抛异常的代码

master
星期八 5 years ago
parent 635ef92e8b
commit d669be0a8e
  1. 3
      proxy-protocol/src/main/java/org/fengfei/lanproxy/protocol/Constants.java
  2. 7
      proxy-server/src/main/java/org/fengfei/lanproxy/server/config/web/HttpRequestHandler.java
  3. 7
      proxy-server/src/main/java/org/fengfei/lanproxy/server/config/web/routes/RouteConfig.java

@ -3,6 +3,9 @@ package org.fengfei.lanproxy.protocol;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.util.AttributeKey; import io.netty.util.AttributeKey;
/**
* 常量类
*/
public interface Constants { public interface Constants {
AttributeKey<Channel> NEXT_CHANNEL = AttributeKey.newInstance("nxt_channel"); AttributeKey<Channel> NEXT_CHANNEL = AttributeKey.newInstance("nxt_channel");

@ -34,6 +34,11 @@ public class HttpRequestHandler extends SimpleChannelInboundHandler<FullHttpRequ
private static final String SERVER_VS = "LPS-0.1"; private static final String SERVER_VS = "LPS-0.1";
/**
* http 斜杠
*/
private static final String HTTP_SYMBOL ="/";
@Override @Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) throws Exception { protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) throws Exception {
@ -76,7 +81,7 @@ public class HttpRequestHandler extends SimpleChannelInboundHandler<FullHttpRequ
HttpResponseStatus status = HttpResponseStatus.OK; HttpResponseStatus status = HttpResponseStatus.OK;
URI uri = new URI(request.getUri()); URI uri = new URI(request.getUri());
String uriPath = uri.getPath(); String uriPath = uri.getPath();
uriPath = uriPath.equals("/") ? "/index.html" : uriPath; uriPath = HTTP_SYMBOL.equals(uriPath)? "/index.html" : uriPath;
String path = PAGE_FOLDER + uriPath; String path = PAGE_FOLDER + uriPath;
File rfile = new File(path); File rfile = new File(path);
if (rfile.isDirectory()) { if (rfile.isDirectory()) {

@ -32,6 +32,11 @@ import io.netty.handler.codec.http.HttpHeaders;
*/ */
public class RouteConfig { public class RouteConfig {
/**
* 登陆url
*/
public static final String LOGIN_URL = "/login";
protected static final String AUTH_COOKIE_KEY = "token"; protected static final String AUTH_COOKIE_KEY = "token";
private static Logger logger = LoggerFactory.getLogger(RouteConfig.class); private static Logger logger = LoggerFactory.getLogger(RouteConfig.class);
@ -67,7 +72,7 @@ public class RouteConfig {
} }
} }
if (!request.getUri().equals("/login") && !authenticated) { if (!LOGIN_URL.equals(request.getUri()) && !authenticated) {
throw new ContextException(ResponseInfo.CODE_UNAUTHORIZED); throw new ContextException(ResponseInfo.CODE_UNAUTHORIZED);
} }

Loading…
Cancel
Save