Skip to content

Enhancement proposal: use Undertow's built-in handlers to serve static content #1346

Closed

Description

@vic0824

Currently, a dedicated handler exists (GetDynamicContentHandler) for serving static content.
In case it is considered useful, another approach would be to assess the feasibility of using the Undertow's built-in handlers to serve static content, in particular the ResourceHandler.
Advantages: slight reduction of code-base size, possibility of caching on server side, slightly better performance (the Undertow implementation uses a statically initialized map of mime types, thus avoiding a long chain of if-then-else).
Disadvantages: not so easy to serve the html files in response to an http request that does not end with .html (at least so far I wasn't able to do it). I also didn't have time to find out if the Undertow handlers can handle also the templating part of GetDynamicContentHandler

The ResourceHandler can be added to the routes like this:

final int cacheTime = 86400; // seconds
ResourceManager classPathManager = new ClassPathResourceManager(HttpServer.class.getClassLoader(), "static");
ResourceManager resourceManager = new CachingResourceManager(100, 65536,
        new DirectBufferCache(1024, 10, 10480), classPathManager, cacheTime);
ResourceHandler resourceHandler = new ResourceHandler(resourceManager);
resourceHandler.setCachable(Predicates.truePredicate());
resourceHandler.setCacheTime(cacheTime);
final PathHandler routes = new PathHandler();
routes.addPrefixPath("/", resourceHandler);

and the html file must be included in the http request: http://[hostname]:[port_number]/index.html

Activity

  1. lvca commented on Nov 24, 2023

    @lvca
    Member

    @vic0824 if you can find a way to make it work, I'd be happy to evaluate the switch. Or if you are using ArcadeDB to serve your static pages too, what about using the default handler for those in your app where you need more speed?

    In the case of ArcadeDB, it's only for Studio, so it's not a big deal.

  2. vic0824 commented on Nov 25, 2023

    @vic0824
    Author

    GetDynamicContentHandler is absolutely fine, there's nothing wrong with it.
    In my project, I have created a new branch which uses MariaDB, to experiment with geometry types, and it seemed strange that I had to write my own handler for such a common task as serving static content, so I did a bit of research and found a way to do it with a few lines of code using the Undertow's ResourceHandler, and I wanted to share this info.
    There is no real need to modify the current ArcadeDB handler.

  3. self-assigned this
    on Nov 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions