Fix error 500

This commit is contained in:
jeffcheasey88 2023-09-09 20:24:01 +02:00
parent d9d602bb83
commit b06ed20afd
3 changed files with 9 additions and 8 deletions

View file

@ -28,7 +28,8 @@ public class Client<U extends User> extends Thread{
reader.readHeaders(); reader.readHeaders();
RequestType type = RequestType.valueOf(headers[0]); RequestType type = RequestType.valueOf(headers[0]);
context = router.exec(type, headers[1], isLogin(router, type, reader), reader, writer); context = new Context(type, headers[1], isLogin(router, type, reader), writer, router.getDefaultHeaders(type));
router.exec(context, reader, writer);
writer.flush(); writer.flush();
writer.close(); writer.close();
}catch(InvalidJwtException e){ }catch(InvalidJwtException e){

View file

@ -31,9 +31,12 @@ public class RouteMapper{
this.dif = 2; this.dif = 2;
} }
public boolean exec(Context context, String path, User user, HttpReader reader, HttpWriter writer) throws Exception{ public boolean exec(Context context, HttpReader reader, HttpWriter writer) throws Exception{
Response result = null; Response result = null;
Matcher matcher = null; Matcher matcher = null;
String path = context.getPath();
synchronized(responses){ synchronized(responses){
for(int i = 0; i < responses.length; i++){ for(int i = 0; i < responses.length; i++){
Response response = responses[i]; Response response = responses[i];
@ -41,7 +44,7 @@ public class RouteMapper{
Pattern pattern = patterns[i]; Pattern pattern = patterns[i];
matcher = pattern.matcher(path); matcher = pattern.matcher(path);
if(matcher.matches()){ if(matcher.matches()){
if(user == null && route.needLogin()){ if((!context.isLogged()) && route.needLogin()){
writer.response(401, "Access-Control-Allow-Origin: *"); writer.response(401, "Access-Control-Allow-Origin: *");
return true; return true;
} }

View file

@ -96,12 +96,9 @@ public class Router<U extends User>{
return this.headers[type.ordinal()]; return this.headers[type.ordinal()];
} }
Context exec(RequestType type, String path, User user, HttpReader reader, HttpWriter writer) throws Exception{ void exec(Context context, HttpReader reader, HttpWriter writer) throws Exception{
if(type == null) return null; if(this.mappers[context.getType().ordinal()].exec(context, reader, writer)) return;
Context context = new Context(type, path, user, writer, this.headers[type.ordinal()]);
if(this.mappers[type.ordinal()].exec(context, path, user, reader, writer)) return context;
if(noFileFound != null) noFileFound.exec(null, context, reader, writer); if(noFileFound != null) noFileFound.exec(null, context, reader, writer);
return context;
} }
public Router<U> configureSSL(String keyStore, String keyStorePassword){ public Router<U> configureSSL(String keyStore, String keyStorePassword){