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' api 'com.google.code.gson:gson:2.8.8'
testImplementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2'
} }
version = "1.0.0" version = "1.0.1"
task classJar(type: Jar, dependsOn: classes) { task classJar(type: Jar, dependsOn: classes) {
classifier = "jar" classifier = "jar"
} }

View File

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