Index: openacs-4/packages/acs-tcl/tcl/utilities-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/utilities-procs.tcl,v diff -u -r1.189.2.176 -r1.189.2.177 --- openacs-4/packages/acs-tcl/tcl/utilities-procs.tcl 5 Jul 2024 13:43:29 -0000 1.189.2.176 +++ openacs-4/packages/acs-tcl/tcl/utilities-procs.tcl 8 Jul 2024 13:20:06 -0000 1.189.2.177 @@ -1964,51 +1964,51 @@ return $result } -ad_proc util::complete_location { - -location:required - -complete_url +ad_proc util::absolute_url { + -url:required + -base_url } { - Completes specified relative URL. When no complete URL is - specified for reference, it will assume the current host as the - server. + Value added version of "ns_absoluteurl" with the following differences + + - keep protocol relative URLs unchanged (no scheme is completed) + - use [util_current_location] as default "base_url" + - allow variable "url" to be empty (replaced by /) + + Completes specified URL when necessary. When no base URL is + specified, it will default to the current location (scheme and host). + The purpose of this utility is to be used by HTTP clients to complete URLs coming from the Location response header in case of a redirect, which according to RFC 7231 may also be relative. - @param location a supposedly relative URL to complete. When the - URL is already complete, it will be returned - as-is. - @param complete_url URL of the redirected request. A complete URL + @param url a supposedly relative URL to complete. When the + URL is already complete, it will be returned + as-is. + @param base_url URL of the redirected request. A complete URL from which we want to read the host. When missing, the URL will be completed using the result of util_current_location. @return a complete absolute URL @see https://www.rfc-editor.org/rfc/rfc7231#section-7.1.2 + @see https://naviserver.sourceforge.io/n/naviserver/files/ns_absoluteurl.html } { - if {![info exists complete_url]} { - set complete_url [util_current_location] - } elseif {![dict exists [ns_parseurl -strict $complete_url] host]} { - error "util::complete_location: '$complete_url' is not a valid complete URL" + if {![info exists base_url]} { + set base_url [util_current_location] } - - set parsed_location [ns_parseurl -strict $location] - if {[dict exists $parsed_location host]} { - return $location + if {[dict exists [ns_parseurl -strict $url] host]} { + return $url } - - util::split_location $complete_url proto hostname port - - set host_url [util::join_location \ - -proto $proto \ - -hostname $hostname \ - -port $port] - - return [ns_absoluteurl $location $host_url] + if {$url eq ""} { + set url / + } + #ns_log notice "================ XXX [list ns_absoluteurl $url $base_url] -> <[ns_absoluteurl $url $base_url]>" + return [ns_absoluteurl $url $base_url] } + ad_proc -public util::configured_location {{-suppress_port:boolean}} { Return the configured location as configured for the current