mraible commented on code in PR #337:
URL: https://github.com/apache/roller/pull/337#discussion_r4609102035
##########
app/src/main/java/org/apache/roller/weblogger/config/WebloggerRuntimeConfig.java:
##########
@@ -168,21 +177,73 @@ public static String getRuntimeConfigDefsAsString() {
/**
- * Special method which sets the non-persisted absolute url to this site.
+ * Set the absolute url of the request being handled on this thread. The
+ * InitFilter sets this at the start of each request and clears it with
+ * clearRequestAbsoluteContextURL() when the request is done.
*
- * This property is *not* persisted in any way.
+ * This value is *not* persisted or shared with other threads.
*/
- public static void setAbsoluteContextURL(String url) {
- absoluteContextURL = url;
+ public static void setRequestAbsoluteContextURL(String url) {
+ requestAbsoluteContextURL.set(url);
}
-
-
+
+
+ /**
+ * Forget the absolute url of the request handled on this thread.
+ */
+ public static void clearRequestAbsoluteContextURL() {
+ requestAbsoluteContextURL.remove();
+ }
+
+
+ /**
+ * True if getAbsoluteContextURL() has returned the current request's url
+ * on this thread. Output built from that url depends on the request's Host
+ * header, so the rendering caches don't store it.
+ */
+ /**
+ * The cache key to use for content rendered for the current request. While
+ * site.absoluteurl is unset, links are built from the request's own URL,
so
+ * the key includes it: content cached for one host name is only served to
+ * requests for that host name.
+ */
+ public static String cacheKey(String key) {
+ String absURL = getProperty("site.absoluteurl");
Review Comment:
Each request now reads site.absoluteurl once, the first time it builds a
link or a cache key, and keeps that value in InitFilter's thread-local, so a
rendering that started while the URL was unset is stored under its per-host key
even if an administrator sets the URL before put(). SiteUrlWhileUnsetTest sets
the property mid-render and checks that a later request doesn't get that
rendering from any of the four caches. The same change is on #320.
##########
app/src/main/java/org/apache/roller/weblogger/config/WebloggerRuntimeConfig.java:
##########
@@ -191,8 +252,44 @@ public static String getAbsoluteContextURL() {
if(absURL != null && !absURL.isBlank()) {
return absURL;
}
-
- return absoluteContextURL;
+
+ if (absoluteURLWarningLogged.compareAndSet(false, true)) {
+ log.warn("The site's absolute URL (site.absoluteurl) is not set,
so "
+ + "links in emails and feeds will use the host name of
each "
+ + "request. Set \"Absolute URL to site\" under Server "
+ + "Administration > Configuration.");
+ }
+
+ return requestAbsoluteContextURL.get();
Review Comment:
MultiPlanetURLStrategy.getPlanetURL() and Roller's PlanetURLStrategy now use
getAbsoluteContextURL(), so planet links use the request URL while the property
is unset. SiteUrlWhileUnsetTest checks the planet, group feed and Roller planet
URLs with the property unset and set. The same change is on #320.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]