mORMot2 icon indicating copy to clipboard operation
mORMot2 copied to clipboard

Use HTTP server as web proxy with cache

Open synopse opened this issue 3 months ago • 1 comments

A caching logic, similar to the PeerCache local temporary cache, is to be used.

For a given URI, e.g. https://mormotcache.ad.company.com/*, we redirect to another server So that e.g. https://mormotcache.ad.company.com/https/srvorigin.ad.company.com/application/file will trigger the following process:

  1. make a HEAD https://srvorigin.ad.company.com/application/file
  2. compute a hash of its URI + last-modify = HASH (not content-length because it may not be available)
  3. check for a local file name from this HASH 4a) if the file exists, change its timestamp to the current time, and serve it to the client 4b) if the file does not exist, start downloading from GET https://srvorigin.ad.company.com, serve it in "progressive" mode (like PeerCache) to the client, then eventually copy the file to the local temporary folder
  4. once in a while, check for deprecated files in the local temporary folder

OnRemoteUri event callback could check for the remote URI validity, with any additional information (e.g. TLS client certificate) for both HEAD and GET.

We can't directly reuse the PeerCache logic for this process, because there is no content hashing, and the actual usecase is not the same.

synopse avatar Sep 30 '25 13:09 synopse

Most of it is implemented.

What is missing is

  • [ ] integrated PeerCache, especially when run on the loopback, for the remote HEAD/GET https://srvorigin.ad.company.com
  • [ ] to use THttpCacheFiles from mormot.net.client.pas to store locally the metadata and not touching the file timestamp (which is confusing) - may be also beneficial to the PeerCache local cache (as option in both places?)

synopse avatar Nov 07 '25 18:11 synopse