[Rt-commit] rt branch, 4.2/canonicalize-urls-in-feeds, created. rt-4.0.4-302-ge28696f

? sunnavy sunnavy at bestpractical.com
Mon Jan 16 09:28:54 EST 2012


The branch, 4.2/canonicalize-urls-in-feeds has been created
        at  e28696f28299c69f670e43dda9251f39bdbf25be (commit)

- Log -----------------------------------------------------------------
commit e28696f28299c69f670e43dda9251f39bdbf25be
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Mon Jan 16 20:37:20 2012 +0800

    add $CanonicalizeURLsInFeeds config
    
    people may use different urls instead of $WebURL in config.
    add this option so they can choose the one used in feeds.

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index d1dbb1b..3523e89 100755
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -852,6 +852,18 @@ enable this option.
 
 Set($CanonicalizeRedirectURLs, 0);
 
+=item C<$CanonicalizeURLsInFeeds>
+
+Set C<$CanonicalizeURLsInFeeds> to 1 to use C<$WebURL> in feeds
+rather than the one we get from C<%ENV>.
+
+If you use RT behind a reverse proxy, you almost certainly want to
+enable this option.
+
+=cut
+
+Set($CanonicalizeURLsInFeeds, 0);
+
 =item C<@JSFiles>
 
 A list of JavaScript files to be included in head.  Removing any of
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index cff7abb..3a33b36 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -744,6 +744,30 @@ sub SendSessionCookie {
     $HTML::Mason::Commands::r->err_headers_out->{'Set-Cookie'} = $cookie->as_string;
 }
 
+=head2 GetWebURLFromENV
+
+People may use different web urls instead of C<$WebURL> in config.
+Return the web url current user is using.
+
+=cut
+
+sub GetWebURLFromENV {
+
+    my $uri = URI->new( RT->Config->Get('WebURL') );
+
+    if ( defined $ENV{HTTPS} and $ENV{'HTTPS'} eq 'on' ) {
+        $uri->scheme('https');
+    }
+    else {
+        $uri->scheme('http');
+    }
+
+    # [rt3.fsck.com #12716] Apache recommends use of $SERVER_HOST
+    $uri->host( $ENV{'SERVER_HOST'} || $ENV{'HTTP_HOST'} || $ENV{'SERVER_NAME'} );
+    $uri->port( $ENV{'SERVER_PORT'} );
+    return "$uri"; # stringify to be consistent with WebURL in config
+}
+
 =head2 Redirect URL
 
 This routine ells the current user's browser to redirect to URL.  
@@ -774,15 +798,10 @@ sub Redirect {
         && $uri->host eq $server_uri->host
         && $uri->port eq $server_uri->port )
     {
-        if ( defined $ENV{HTTPS} and $ENV{'HTTPS'} eq 'on' ) {
-            $uri->scheme('https');
-        } else {
-            $uri->scheme('http');
-        }
-
-        # [rt3.fsck.com #12716] Apache recommends use of $SERVER_HOST
-        $uri->host( $ENV{'SERVER_HOST'} || $ENV{'HTTP_HOST'} || $ENV{'SERVER_NAME'});
-        $uri->port( $ENV{'SERVER_PORT'} );
+        my $env_uri = URI->new(GetWebURLFromENV());
+        $uri->scheme($env_uri->scheme);
+        $uri->host($env_uri->host);
+        $uri->port($env_uri->port);
     }
 
     # not sure why, but on some systems without this call mason doesn't
diff --git a/share/html/NoAuth/iCal/dhandler b/share/html/NoAuth/iCal/dhandler
index c967ce4..8e480be 100644
--- a/share/html/NoAuth/iCal/dhandler
+++ b/share/html/NoAuth/iCal/dhandler
@@ -93,8 +93,17 @@ while (my $t = $tickets->Next) {
     my $now = RT::Date->new( $cu ); $now->SetToNow;
     my $start = Data::ICal::Entry::Event->new;
     my $end   = Data::ICal::Entry::Event->new;
+
+    my $url;
+    if ( RT->Config->Get('CanonicalizeURLsInFeeds') ) {
+        $url = RT->Config->Get('WebURL');
+    }
+    else {
+        $url = RT::Interface::Web::GetWebURLFromENV();
+    }
+
     $_->add_properties(
-        url       => RT->Config->Get('WebURL') . "?q=".$t->id,
+        url       => $url . "?q=".$t->id,
         organizer => $t->OwnerObj->Name,
         dtstamp   => $now->iCal,
         created   => $t->CreatedObj->iCal,
diff --git a/share/html/Search/Elements/ResultsRSSView b/share/html/Search/Elements/ResultsRSSView
index 4aa3dc1..2137b41 100644
--- a/share/html/Search/Elements/ResultsRSSView
+++ b/share/html/Search/Elements/ResultsRSSView
@@ -103,9 +103,18 @@ $r->content_type('application/rss+xml');
         # create an RSS 1.0 file (http://purl.org/rss/1.0/)
         use XML::RSS;
         my $rss = XML::RSS->new(version => '1.0');
+
+        my $url;
+        if ( RT->Config->Get('CanonicalizeURLsInFeeds') ) {
+            $url = RT->Config->Get('WebURL');
+        }
+        else {
+            $url = RT::Interface::Web::GetWebURLFromENV();
+        }
+
         $rss->channel(
           title        => RT->Config->Get('rtname').": Search " . $ARGS{'Query'},
-          link         => RT->Config->Get('WebURL'),
+          link         => $url,
           description  => "",
           dc => {
           },
@@ -123,7 +132,7 @@ $r->content_type('application/rss+xml');
         $creator_str =~ s/[\r\n]//g;
         $rss->add_item(
           title       =>  $Ticket->Subject || loc('No Subject'),
-          link        => RT->Config->Get('WebURL')."Ticket/Display.html?id=".$Ticket->id,
+          link        => $url . "Ticket/Display.html?id=".$Ticket->id,
           description => $Ticket->Transactions->First->Content,
           dc          => { creator => $creator_str,
                            date => $Ticket->CreatedObj->RFC2822,

-----------------------------------------------------------------------


More information about the Rt-commit mailing list