This library provides a thymeleaf3 dialect that resolves esi:include tags.
When property esiinclude-thymeleaf-dialect.dialect-enabled
is true
, esi-includes will be resolved and their responses put into the output stream of the webpage.
-
Add a dependency to this library to your project:
implementation de.otto:esi-include-thymeleaf3-dialect:<version>
-
Provide a Fetch function that is used to resolve esi includes. If a dependency to
com.ning:async-http-client
is present, such a function is provided automatically.Otherwise you need to provide a spring bean with type Fetch yourself. The function takes the source url as its argument and returns a
Response
object.Make sure that your Fetch-function handles redirects, as this library does not do it.
-
Set property
esiinclude-thymeleaf-dialect.dialectEnabled
totrue
so that the esi dialect is actually used -
Optional: Set property
esiinclude-thymeleaf-dialect.prefixForRelativePath
to[http|https]://<hostname>
to prefix relative esi:include src urls. -
Optional: Set property
esiinclude-thymeleaf-dialect.proxyEnabled
totrue
to enable and start a local proxy. This proxy sets the headerAccess-Control-Allow-Origin
to*
so that problems with CORS are prevented.The following properties configure the proxy:
proxyRedirectProtocol
- protocol used for redirects, default ishttps
proxyRedirectHost
- host where to redirect toproxyPort
- port where the proxy is listening, default is8085
- Update to spring boot 3.2.2
- Build with java 17 / gradle 8
- Update to spring boot 3 / spring 6
- Add property
enabled-uris
. It's now possible to restrict resolving of esi includes. When set only esi includes that are contained in responses of request uris that start with one of the configuredenabled-uris
are resolved. When not set, all esi includes are resolved as before.
- Updates to Spring 5.x, Spring Boot 2.x
- Remove default fetch configuration
- Provide default fetch implementation even when
dialect-enabled
is false since it is used by both the proxy and the esi dialect.
- Fix logging
- Catch BindException when proxy port is already in use. This may happen during spring integration tests when spring caches multiple application contexts.
- Stop proxy on context shutdown in @PreDestroy
- Activate esi dialect by property
esiinclude-thymeleaf-dialect.dialect-enabled
instead of by spring profiles
- Add properties
esiinclude-thymeleaf-dialect.proxy-redirect-host
andesiinclude-thymeleaf-dialect.proxy-redirect-scheme
to make redirect host and scheme configurable.
- Extract EsiContentResolver into separate Bean.
- Add proxy to avoid CORS errors when resources are loaded within an esi-included page. Proxy can be enabled using the property
esiinclude-thymeleaf-dialect.proxy-enabled
. The port can be set withesiinclude-thymeleaf-dialect.proxy-port
, default is8085
.
-
Add spring properties bean for property
esiinclude-thymeleaf-dialect.prefixForRelativePath
so that you get syntax highlighting and code completion in your application*.yml files in your IDE.This property may now also be written "
prefix-for-relative-path
"
- Add javadoc
- Rename variables and httpClient to Fetch
- Rename property
esiinclude-thymeleaf-dialect.hostname
toesiinclude-thymeleaf-dialect.prefixForRelativePath
Provide asyncHttpClient as httpClient when com.ning:async-http-client dependency is provided
Initial version