Search in sources :

Example 1 with HttpServer

use of suite.http.HttpServer in project suite by stupidsing.

the class ServerMain method runHttpServer.

private void runHttpServer() {
    Authenticator authenticator = (username, password) -> Constants.secrets().prove(Suite.substitute("auth .0 .1", new Str(username), new Str(password)));
    HttpHandler handler0 = request -> HttpResponse.of(To.outlet(// 
    "" + // 
    "<html>" + "<br/>method = " + // 
    request.method + "<br/>server = " + // 
    request.server + "<br/>path = " + // 
    request.path + "<br/>attrs = " + // 
    HttpHeaderUtil.getAttrs(request.query) + "<br/>headers = " + // 
    request.headers + "</html>"));
    HttpHandler handler1 = HttpHandler.ofDispatch(// 
    IMap.<String, HttpHandler>empty().put("path", // 
    HttpHandler.ofPath(Constants.tmp)).put("site", HttpHandler.ofSession(authenticator, handler0)));
    new HttpServer().run(handler1);
}
Also used : HttpHandler(suite.http.HttpHandler) Schedule(suite.os.Schedule) ExecutableProgram(suite.util.RunUtil.ExecutableProgram) IMap(suite.immutable.IMap) LocalDateTime(java.time.LocalDateTime) Thread_(suite.util.Thread_) HttpHeaderUtil(suite.http.HttpHeaderUtil) To(suite.util.To) Scheduler(suite.os.Scheduler) RunUtil(suite.util.RunUtil) ArrayList(java.util.ArrayList) TelegramBot(suite.telegram.TelegramBot) List(java.util.List) HttpServer(suite.http.HttpServer) Authenticator(suite.http.HttpSessionController.Authenticator) LocalTime(java.time.LocalTime) HttpResponse(suite.http.HttpResponse) Str(suite.node.Str) Str(suite.node.Str) HttpHandler(suite.http.HttpHandler) HttpServer(suite.http.HttpServer) Authenticator(suite.http.HttpSessionController.Authenticator)

Aggregations

LocalDateTime (java.time.LocalDateTime)1 LocalTime (java.time.LocalTime)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 HttpHandler (suite.http.HttpHandler)1 HttpHeaderUtil (suite.http.HttpHeaderUtil)1 HttpResponse (suite.http.HttpResponse)1 HttpServer (suite.http.HttpServer)1 Authenticator (suite.http.HttpSessionController.Authenticator)1 IMap (suite.immutable.IMap)1 Str (suite.node.Str)1 Schedule (suite.os.Schedule)1 Scheduler (suite.os.Scheduler)1 TelegramBot (suite.telegram.TelegramBot)1 RunUtil (suite.util.RunUtil)1 ExecutableProgram (suite.util.RunUtil.ExecutableProgram)1 Thread_ (suite.util.Thread_)1 To (suite.util.To)1