Index: openacs-4/packages/acs-tcl/tcl/00-icanuse-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/00-icanuse-procs.tcl,v
diff -u -r1.1.2.47 -r1.1.2.48
--- openacs-4/packages/acs-tcl/tcl/00-icanuse-procs.tcl	25 Feb 2024 15:46:51 -0000	1.1.2.47
+++ openacs-4/packages/acs-tcl/tcl/00-icanuse-procs.tcl	17 May 2024 14:05:50 -0000	1.1.2.48
@@ -139,12 +139,17 @@
 ::acs::register_icanuse "nsv_dict"                  [acs::cmd_error_contains {ns_trim} -prefix]
 
 #
+# At the time "ns_ip" was introduced in NaviServer, the member
+# "proxied" was added to the result of "ns_conn details".
+
+::acs::register_icanuse "ns_conn proxied" {[info commands ::ns_ip] ne ""}
+
+#
 # When "nsf::parseargs -asdict" was introduced, the object aliasing
 # was also introduced in nsf. .... But this feature is not ready yet.
 #
 #::acs::register_icanuse "nx::alias object"          [acs::cmd_error_contains {nsf::parseargs} -asdict]
 
-
 #
 # The following commands check indirectly the availability, since the
 # commands require connections etc.  These features were introduced
Index: openacs-4/packages/acs-tcl/tcl/request-processor-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/request-processor-procs.tcl,v
diff -u -r1.153.2.59 -r1.153.2.60
--- openacs-4/packages/acs-tcl/tcl/request-processor-procs.tcl	24 Jul 2023 12:59:24 -0000	1.153.2.59
+++ openacs-4/packages/acs-tcl/tcl/request-processor-procs.tcl	17 May 2024 14:05:50 -0000	1.153.2.60
@@ -1715,6 +1715,9 @@
                                     return [ns_set value $headers $i]
                                 }
                             }
+                            #
+                            # Default for newer versions of NaviServer
+                            #
                             return [set ad_conn(peeraddr) [ns_conn peeraddr]]
                         }
 
@@ -1768,16 +1771,30 @@
                         }
 
                         behind_proxy_p {
-                            #
-                            # Check, if we are running behind a proxy:
-                            # a) the parameter "ReverseProxyMode" has to be set
-                            # b) the header-field X-Forwarded-For must be present
-                            #
-                            set ad_conn(behind_proxy_p) 0
+                            set ad_conn(ajax_p) 0
                             if {[ns_conn isconnected]} {
-                                if { [ns_config "ns/parameters" ReverseProxyMode false]
-                                     && [ns_set ifind [ns_conn headers] X-Forwarded-For] > -1} {
-                                    set ad_conn(behind_proxy_p) 1
+
+                                if {[acs::icanuse "ns_conn proxied"]} {
+                                    #
+                                    # Newer versions of NaviServer
+                                    # provide feedback, whteher the
+                                    # peer was connected via a
+                                    # reqverse proxy or direct.
+                                    #
+                                    set ad_conn(behind_proxy_p) [dict get [ns_conn details] proxied]
+                                } else {
+                                    #
+                                    # Check, if we are running behind a proxy:
+                                    # a) the parameter "ReverseProxyMode" has to be set
+                                    # b) the header-field X-Forwarded-For must be present
+                                    #
+
+                                    if {[ns_conn isconnected]} {
+                                        if { [ns_config "ns/parameters" ReverseProxyMode false]
+                                             && [ns_set ifind [ns_conn headers] X-Forwarded-For] > -1} {
+                                            set ad_conn(behind_proxy_p) 1
+                                        }
+                                    }
                                 }
                             }
                             return $ad_conn(behind_proxy_p)