snoopdave commented on code in PR #337:
URL: https://github.com/apache/roller/pull/337#discussion_r4608405369


##########
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:
   **Blocking:** A render can build links while `site.absoluteurl` is unset, 
then call a cache `put()` after an administrator sets it. `cacheKey()` then 
returns the shared key, allowing that earlier rendering to be served on later 
requests. Keep the key mode fixed for the render, or prevent an in-flight 
render from writing under the shared key when the property changes.



##########
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:
   **Important:** `MultiPlanetURLStrategy.getPlanetURL()` still reads 
`site.absoluteurl` directly. While it is unset, `PlanetModel` can render 
`null/ignored/` and related group or feed links despite this request URL 
fallback. Route that strategy through `getAbsoluteContextURL()` and test the 
unset-property case.



-- 
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]

Reply via email to