[Rt-commit] rt branch, 4.2/canonicalize-urls-in-feeds, created. rt-4.1.17-140-g03aee7f

Alex Vandiver alexmv at bestpractical.com
Fri Jul 26 18:49:44 EDT 2013


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

- Log -----------------------------------------------------------------
commit c7ce31acccfb6c503d6da603a02c9f5dc4ef564d
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 82e55b4..12f2e2b 100755
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -920,6 +920,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 additional JavaScript files to be included in head.
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index 01c6495..2f41c86 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -893,6 +893,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.  
@@ -923,15 +947,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 d4c2e05..daf0b59 100644
--- a/share/html/NoAuth/iCal/dhandler
+++ b/share/html/NoAuth/iCal/dhandler
@@ -89,17 +89,27 @@ while (my $t = $tickets->Next) {
     next unless $t->DueObj->Unix > 0;
 
     my $starttime = $t->StartsObj->Unix > 0 ? $t->StartsObj : $t->CreatedObj;
-    my $url = RT->Config->Get('WebURL') . "Ticket/Display.html?id=".$t->id,
+
+    my $url;
+    if ( RT->Config->Get('CanonicalizeURLsInFeeds') ) {
+        $url = RT->Config->Get('WebURL');
+    }
+    else {
+        $url = RT::Interface::Web::GetWebURLFromENV();
+    }
+    $url .= "Ticket/Display.html?id=".$t->id,
 
     my $now = RT::Date->new( $cu ); $now->SetToNow;
     my $start = Data::ICal::Entry::Event->new;
     my $end   = Data::ICal::Entry::Event->new;
+
+
     $_->add_properties(
-        url       => $url,
-        description => $url,
-        organizer => $t->OwnerObj->Name,
-        dtstamp   => $now->iCal,
-        created   => $t->CreatedObj->iCal,
+        url            => $url,
+        description    => $url,
+        organizer      => $t->OwnerObj->Name,
+        dtstamp        => $now->iCal,
+        created        => $t->CreatedObj->iCal,
        'last-modified' => $t->LastUpdatedObj->iCal,
     ) for $start, $end;
 
diff --git a/share/html/Search/Elements/ResultsRSSView b/share/html/Search/Elements/ResultsRSSView
index 5a16e65..6d3789c 100644
--- a/share/html/Search/Elements/ResultsRSSView
+++ b/share/html/Search/Elements/ResultsRSSView
@@ -103,9 +103,18 @@ $r->content_type('application/rss+xml; charset=utf-8');
         # 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; charset=utf-8');
         $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,

commit 5d61fc675f7505940b779df7375e6d46670f4541
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Jan 17 01:52:13 2012 +0800

    GetWebURLFromENV is a bad name, change to GetWebURLFromRequest

diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index 2f41c86..c8b91be 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -893,14 +893,14 @@ sub SendSessionCookie {
     $HTML::Mason::Commands::r->err_headers_out->{'Set-Cookie'} = $cookie->as_string;
 }
 
-=head2 GetWebURLFromENV
+=head2 GetWebURLFromRequest
 
 People may use different web urls instead of C<$WebURL> in config.
 Return the web url current user is using.
 
 =cut
 
-sub GetWebURLFromENV {
+sub GetWebURLFromRequest {
 
     my $uri = URI->new( RT->Config->Get('WebURL') );
 
@@ -947,7 +947,7 @@ sub Redirect {
         && $uri->host eq $server_uri->host
         && $uri->port eq $server_uri->port )
     {
-        my $env_uri = URI->new(GetWebURLFromENV());
+        my $env_uri = URI->new(GetWebURLFromRequest());
         $uri->scheme($env_uri->scheme);
         $uri->host($env_uri->host);
         $uri->port($env_uri->port);
diff --git a/share/html/NoAuth/iCal/dhandler b/share/html/NoAuth/iCal/dhandler
index daf0b59..988488f 100644
--- a/share/html/NoAuth/iCal/dhandler
+++ b/share/html/NoAuth/iCal/dhandler
@@ -95,7 +95,7 @@ while (my $t = $tickets->Next) {
         $url = RT->Config->Get('WebURL');
     }
     else {
-        $url = RT::Interface::Web::GetWebURLFromENV();
+        $url = RT::Interface::Web::GetWebURLFromRequest();
     }
     $url .= "Ticket/Display.html?id=".$t->id,
 
diff --git a/share/html/Search/Elements/ResultsRSSView b/share/html/Search/Elements/ResultsRSSView
index 6d3789c..0d74b11 100644
--- a/share/html/Search/Elements/ResultsRSSView
+++ b/share/html/Search/Elements/ResultsRSSView
@@ -109,7 +109,7 @@ $r->content_type('application/rss+xml; charset=utf-8');
             $url = RT->Config->Get('WebURL');
         }
         else {
-            $url = RT::Interface::Web::GetWebURLFromENV();
+            $url = RT::Interface::Web::GetWebURLFromRequest();
         }
 
         $rss->channel(

commit 03aee7fccee54f8c4efd8ffc17e0516afcd0b7bc
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue Jan 17 02:03:01 2012 +0800

    "%ENV" is implementation details, "request" is better

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index 12f2e2b..71bcd54 100755
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -923,7 +923,7 @@ 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>.
+rather than the one we get from request.
 
 If you use RT behind a reverse proxy, you almost certainly want to
 enable this option.

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


More information about the Rt-commit mailing list