Compare commits

..

No commits in common. "7be045fdb4c5ed904651daffa517d8c6d34d3d68" and "8ea733c63706d103a9728acf6230de22241b1fb3" have entirely different histories.

2 changed files with 6 additions and 10 deletions

View file

@ -26,7 +26,7 @@ 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 = new Context(type, headers[1], isLogin(type, reader), writer, router.getDefaultHeaders(type)); context = new Context(type, headers[1], isLogin(router, type, reader), writer, router.getDefaultHeaders(type));
router.exec(context, reader, writer); router.exec(context, reader, writer);
writer.flush(); writer.flush();
writer.close(); writer.close();
@ -44,7 +44,7 @@ public class Client<U extends User> extends Thread{
if(context != null) logger.setValue(context); if(context != null) logger.setValue(context);
} }
private User isLogin(RequestType type, HttpReader reader) throws InvalidJwtException{ private User isLogin(Router<U> router, RequestType type, HttpReader reader) throws InvalidJwtException{
String auth = reader.getHeader("Authorization"); String auth = reader.getHeader("Authorization");
if(auth == null) return null; if(auth == null) return null;
auth = auth.substring(7); auth = auth.substring(7);
@ -52,7 +52,7 @@ public class Client<U extends User> extends Thread{
return this.router.getUser(auth); return this.router.getUser(auth);
}catch(InvalidJwtException e){ }catch(InvalidJwtException e){
try{ try{
writer.response(401, this.router.getDefaultHeaders(type)); writer.response(401, router.getDefaultHeaders(type));
writer.flush(); writer.flush();
writer.close(); writer.close();
}catch(Exception ex){} }catch(Exception ex){}

View file

@ -45,11 +45,7 @@ public class JsonParser extends Parser<Json>{
content.then(new RedirectStateTree<>(base, (global, local) -> global.set(local.get()))).end(); content.then(new RedirectStateTree<>(base, (global, local) -> global.set(local.get()))).end();
content.then((validator) -> validator.validate((token) -> token.getType().equals(TokenType.STRING), (bag, token) -> bag.set(token))).end(); content.then((validator) -> validator.validate((token) -> token.getType().equals(TokenType.STRING), (bag, token) -> bag.set(token))).end();
content.then((validator) -> validator.validate((token) -> token.getType().equals(TokenType.CHAR), (bag, token) -> bag.set(token))).end(); content.then((validator) -> validator.validate((token) -> token.getType().equals(TokenType.CHAR), (bag, token) -> bag.set(token))).end();
StateTree<Json> number = content.then((validator) -> validator.validate((token) -> token.getType().equals(TokenType.NAME), (bag, token) -> bag.set(token))); content.then((validator) -> validator.validate((token) -> token.getType().equals(TokenType.NAME), (bag, token) -> bag.set(token))).end();
number.end();
number.then((validator) -> validator.validate((token) -> token.getValue().equals("."), (bag, token) -> bag.set(bag.<Token>get().concat(token))))
.then((validator) -> validator.validate((token) -> token.getType().equals(TokenType.NAME), (bag, token) -> bag.set(bag.<Token>get().concat(token))))
.end();
StateTree<Json> mapper = new StateTree<>(); StateTree<Json> mapper = new StateTree<>();
StateTree<Json> mapper_key = mapper.then((validator) -> validator.validate((token) -> token.getType().equals(TokenType.STRING), (bag, token) -> { StateTree<Json> mapper_key = mapper.then((validator) -> validator.validate((token) -> token.getType().equals(TokenType.STRING), (bag, token) -> {
@ -114,10 +110,10 @@ public class JsonParser extends Parser<Json>{
return Long.parseLong(content); return Long.parseLong(content);
}catch(Exception _){ }catch(Exception _){
try { try {
return Double.parseDouble(content); return Boolean.parseBoolean(content);
}catch(Exception __){ }catch(Exception __){
try{ try{
return Boolean.parseBoolean(content); return Double.parseDouble(content);
}catch(Exception ___){} }catch(Exception ___){}
} }
} }