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


##########
app/src/main/java/org/apache/roller/weblogger/config/WebloggerRuntimeConfig.java:
##########
@@ -192,8 +253,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();
+    }
+
+
+    /**
+     * Save the given url as site.absoluteurl if that property is empty.
+     * Called when the site is being set up, by the installer and by the
+     * registration of the first administrator.
+     *
+     * @return true if the url was saved; the caller must flush
+     */
+    public static boolean saveAbsoluteContextURLIfUnset(String url)
+            throws WebloggerException {
+
+        if (url == null || url.isBlank()) {
+            return false;
+        }
+        PropertiesManager pmgr = 
WebloggerFactory.getWeblogger().getPropertiesManager();
+        RuntimeConfigProperty prop = pmgr.getProperty("site.absoluteurl");

Review Comment:
   **Important:** `saveAbsoluteContextURLIfUnset()` reads and writes the 
property separately. Concurrent administrator requests can both see it unset, 
allowing the later write to replace the first URL. Use 
`PropertiesManager.compareAndSetProperty()` for the existing empty property and 
test that only one concurrent request wins.



##########
app/src/main/java/org/apache/roller/weblogger/config/WebloggerRuntimeConfig.java:
##########
@@ -169,21 +178,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");
+        if (absURL != null && !absURL.isBlank()) {
+            return key;
+        }
+        String requestURL = requestAbsoluteContextURL.get();
+        return requestURL == null ? key : key + "|" + requestURL;

Review Comment:
   **Important:** `WeblogCacheWarmupJob` runs outside `InitFilter`, so while 
the site URL is unset it can render a feed with missing absolute links and 
cache it under the unsuffixed key. After the URL is saved, requests use that 
same key and can receive the warmed feed. Skip background cache writes while 
the URL is unset, or clear the feed cache when the URL is saved; test that 
transition.



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