merge update

This commit is contained in:
CaiHQ 2024-05-23 20:13:33 +08:00
parent dffcadd116
commit 1785426e53
2 changed files with 25 additions and 13 deletions

View File

@ -30,7 +30,7 @@ dependencies {
api 'com.google.code.gson:gson:2.8.8'
testImplementation 'junit:junit:4.13.2'
}
version = "1.0.0"
version = "1.0.1"
task classJar(type: Jar, dependsOn: classes) {
classifier = "jar"
}

View File

@ -17,7 +17,7 @@ import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
public class URIHandler {
private static final Logger LOGGER = LogManager.getLogger(URIHandler.class);
Map<io.netty.handler.codec.http.HttpMethod, List<Tuple<String, Method, Object>>> handlers;
private Map<io.netty.handler.codec.http.HttpMethod, List<Tuple<String, Method, Object>>> handlers;
public URIHandler() {
handlers = new HashMap<>();
@ -59,14 +59,26 @@ public class URIHandler {
});
}
public void handle(ChannelHandlerContext ctx, FullHttpRequest msg) {
try {
public Tuple<String, Method, Object> findHandler(FullHttpRequest msg) {
List<Tuple<String, Method, Object>> handlerList = handlers.get(msg.method());
for (Tuple<String, Method, Object> t : handlerList)
if (msg.uri().startsWith(t.t)) {
t.u.invoke(t.s, ctx, msg);
return;
return t;
}
return null;
}
public void handle(ChannelHandlerContext ctx, FullHttpRequest msg) {
Tuple<String, Method, Object> t = findHandler(msg);
handle(ctx, msg, t);
}
public void handle(ChannelHandlerContext ctx, FullHttpRequest msg,
Tuple<String, Method, Object> t) {
try {
if (t != null)
t.u.invoke(t.s, ctx, msg);
else
sendUnsupported(ctx);
} catch (Exception e) {
e.printStackTrace();
@ -95,10 +107,10 @@ public class URIHandler {
ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
}
static class Tuple<T, U, S> {
T t;
U u;
S s;
public static class Tuple<T, U, S> {
public T t;
public U u;
public S s;
Tuple(T t, U u, S s) {
this.t = t;