From f473139a3a5de6094867ca6c63d6846e2f365202 Mon Sep 17 00:00:00 2001 From: Sergey Linev Date: Fri, 10 Jan 2025 10:06:45 +0100 Subject: [PATCH] Update httpserver docu about custom requests --- docs/HttpServer.md | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/docs/HttpServer.md b/docs/HttpServer.md index 8e8afab82..17f93b61d 100644 --- a/docs/HttpServer.md +++ b/docs/HttpServer.md @@ -592,7 +592,7 @@ Here argument "multi" identifies, that server response should be parsed with `pa ## Using unix sockets -Starting from ROOT version 6.28, one can start server with unix socket. Just do: +Starting from ROOT version 6.28, one can start server bind to the unix socket. Just do: Just call: ```cpp @@ -679,3 +679,26 @@ serv->Register(handler); After that web socket connection can be established with the address `ws://host_name:8080/name1/root.websocket` Example client code can be found in `$ROOTSYS/tutorials/http/ws.htm` file. Custom HTML page for websocket handler is specified with `TUserHandler::GetDefaultPageContent()` method returning `"file:ws.htm"`. + + +## Processing of custom http requests + +To process custom http requests, one can derive from THttpServer class and +reimplement `THttpServer::MissedRequest()` method. Like: + +```cpp +class TCustomHttpServer : public THttpServer { + + TCustomHttpServer(const char *engine) : THttpServer(engine) {} + + void MissedRequest(THttpCallArg *arg) override + { + if (!strcmp(arg->GetPathName(), "custom_path") && + !strcmp(arg->GetFileName(), "empty_object.json")) { + arg->SetJsonContent("{}"); + } else { + THttpServer::MissedRequest(arg); + } + } +}; +``` \ No newline at end of file