Serve Folders plugin and IncomingHttpRequestFilter

Is the IncomingHttpRequestFilter hook invoked for URI served from the Serve Folders plugin?

I’m interested in creating a page to be served using the Serve Folders plugin. The page will be dynamically created by a Lua script. I’m wondering if I could trigger the creation by hooking into the IncomingHttpRequestFilter, assuming it’s called in this case.

Something like:

  1. User attempts to visit /serve/folder/somepage.html in a browser

  2. IncomingHttpRequestFilter intercepts the request

  • Recognizes the URI requested
  • Initiates a Lua script to dynamically create somepage.html
  • Returns true to let the request go through1. Having passed IncomingHttpRequestFilter, the newly generated page is served

One concern might be that the requesting browser would time out while waiting for the Filter request to return true/false if the page generation took too long.



You will not be able to use the “IncomingHttpRequestFilter” Lua for this purpose, as this function has no primitive to answer with a HTML body.

For the time being, the only way to dynamically generate a HTTP answer from within Orthanc is by creating a dedicated C/C++ plugin.

You could create a C/C++ plugin that would provide a wrapper to Lua. Concretely, this plugin would run an embedded Lua engine (e.g. by reusing the “Core/Lua/LuaContext.h” class from the Orthanc core), and would use the traditional “OrthancPluginRegisterRestCallback()” to branch this Lua engine behind some URI endpoint of the REST API of Orthanc.

If other users show interest in this feature, I might consider it for addition inside the official sample plugin ServeFolders.

External contributors are also kindly invited to implement such a plugin.



Thanks for responding, Sebastien.

I was able to accomplish something like what I described entirely in Lua using the IncomingHttpRequestFilter and the ServeFoldersPlugin.

  1. User requests some page from the ServeFolders area: /serve/folder/somepage_A.html
  • somepage_A.html already exists

  • somepage_A.html contains a link to somepage_B.html which may or may not exist1. IncomingHttpRequestFilter

  • Catches the incoming GET by matching the URI /serve/folder/sompage_A.html

  • Being a Lua script, can access and call a previously uploaded Lua script

  • Generates the contents and writes them to /serve/folder/somepage_B.html.

  • This takes time and presents a delay before returning to the calling IncomingHttpRequestsFilter.- Returns “true” to allow user to proceed to somepage_A.html1. /serve/folder/somepage_A.html contains a link to the created /serve/folder/somepage_B.html

  1. User can now load somepage_B.html directly in the future (or update it by calling somepage_A.html)