codemicro · git.akpain.net

A small proxy server that expands esi:include tags within HTML documents


This is a small proxy server that is designed, primarily, to add a little bit of interactivity to static websites. It accepts incoming requests on a HTTP port and forwards them to an upstream server like-for-like. The response is then conditionally checked for <esi:include> tags and returned to the client.

The response parsing is done based on the following rules:

  • If any of the following checks fail, return the entire response (including headers) as-is, without modification:
    • Is the response status code in the 2xx range?
    • Does the Content-Type header contain text/html?
    • Is the first character of the response body <?
  • Are there any <esi:include src="/path"> blocks in the response body?
    • Yes: expand those blocks using the entire response from $ESI_INCLUDES_URL/path, ignoring any other attributes, and removing the Etag and Last-Modified headers from the main response if they are set
    • No: return the entire response as-is, without modification

It is configured with the following environment variables:

  • ESI_HTTP_PORT: port to run the proxy's HTTP server on (default 5000)
  • ESI_HTTP_HOST: hostname to run the proxy's HTTP server on (default 0.0.0.0)
  • ESI_UPSTREAM_URL: the base URL to forward requests to
  • ESI_INCLUDES_URL: the base URL used for ESI requests
  • ESI_REQUEST_TIMEOUT_SECONDS: the timeout used for all requests made by the proxy (default 10 seconds)

Limitations

  • No caching
  • Very limited ESI support (ie. just <esi:include path="">)

Read the original on git.akpain.net ↗