File tree Expand file tree Collapse file tree 2 files changed +26
-10
lines changed
ModuLake-Server/src/main/java/com/eternalstarmc/modulake Expand file tree Collapse file tree 2 files changed +26
-10
lines changed Original file line number Diff line number Diff line change 77import io .vertx .core .http .HttpServerResponse ;
88import io .vertx .ext .web .RoutingContext ;
99
10+ import java .util .Arrays ;
1011import java .util .List ;
1112import java .util .Map ;
1213
@@ -24,7 +25,8 @@ public void handle(RoutingContext context) {
2425 } else {
2526 HttpServerResponse response = context .response ();
2627 response .putHeader ("Content-Type" , "application/json; Charset=UTF-8" );
27- String [] paths = context .request ().path ().split ("/" );
28+ String normalizedPath = context .request ().path ().replaceAll ("/+$" , "" );
29+ String [] paths = normalizedPath .split ("/" );
2830 if (paths .length < 3 ) {
2931 response .setStatusCode (404 ).end (GSON .toJson (Map .of ("response" , "failed" ,
3032 "msg" , "Not found!" )));
@@ -47,6 +49,8 @@ public void handle(RoutingContext context) {
4749 code = 405 ;
4850 data = Map .of ("response" , "failed" ,
4951 "msg" , "Method not allowed!" );
52+ String allowHeader = String .join (", " , Arrays .stream (router .getMethods ()).map (HttpMethod ::name ).toList ());
53+ response .putHeader ("Allow" , allowHeader );
5054 }
5155 }
5256 response .setStatusCode (code ).end (GSON .toJson (data ));
Original file line number Diff line number Diff line change @@ -21,22 +21,34 @@ public PluginClassLoaderImpl(URL[] urls) {
2121
2222 @ Override
2323 protected Class <?> findClass (String name ) throws ClassNotFoundException {
24+ Class <?> loadedClass = findLoadedClass (name );
25+ if (loadedClass != null ) {
26+ return loadedClass ;
27+ }
2428 try {
25- return super .findClass (name );
29+ loadedClass = super .findClass (name );
2630 } catch (ClassNotFoundException ignored ) {}
27-
28- // 遍历所有依赖,直到找到类或全部检查完
29- for (PluginClassLoaderImpl clazzLoader : dependencies .values ()) {
30- try {
31- return clazzLoader .findClass0 (name );
32- } catch (ClassNotFoundException ignored ) {
31+ if (loadedClass == null ) {
32+ for (PluginClassLoaderImpl clazzLoader : dependencies .values ()) {
33+ try {
34+ loadedClass = clazzLoader .findClass0 (name );
35+ if (loadedClass != null ) break ;
36+ } catch (ClassNotFoundException ignored ) {
37+ }
3338 }
3439 }
35- throw new ClassNotFoundException (name );
36- }
3740
41+ if (loadedClass == null ) {
42+ throw new ClassNotFoundException (name );
43+ }
44+ return loadedClass ;
45+ }
3846
3947 protected Class <?> findClass0 (String name ) throws ClassNotFoundException {
48+ Class <?> loadedClass = findLoadedClass (name );
49+ if (loadedClass != null ) {
50+ return loadedClass ;
51+ }
4052 return super .findClass (name );
4153 }
4254
You can’t perform that action at this time.
0 commit comments