[Jifty-commit] jifty branch, master, updated. 1.10518-39-gb562c7e

Jifty commits jifty-commit at lists.jifty.org
Fri Jul 15 11:17:07 EDT 2011


The branch, master has been updated
       via  b562c7efe95b9df2ae009697d828f8f4da021ba7 (commit)
      from  0e4c9f566e159b199760e7371c3fb5da2880fcf3 (commit)

Summary of changes:
 lib/Jifty/Web.pm |   26 +++++++++++++++-----------
 1 files changed, 15 insertions(+), 11 deletions(-)

- Log -----------------------------------------------------------------
commit b562c7efe95b9df2ae009697d828f8f4da021ba7
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Fri Jul 15 10:50:14 2011 -0400

    Force the default configured URL when called from a Jifty::Notification
    
    This means we respect your canonical hostname and scheme instead of
    basing it on the irrelevant current request that caused the email
    generation.
    
    Cloning fixes a bug where we forced scheme to http but didn't touch
    port, potentially leaving it as 443 and generating URLs like
    http://example.com:443/.

diff --git a/lib/Jifty/Web.pm b/lib/Jifty/Web.pm
index 6bb7baf..f2d03cd 100644
--- a/lib/Jifty/Web.pm
+++ b/lib/Jifty/Web.pm
@@ -127,6 +127,9 @@ sub url {
                 path => undef,
                 @_);
 
+    my $base_uri = URI->new(Jifty->config->framework("Web")->{BaseURL});
+    $base_uri->port(Jifty->config->framework("Web")->{Port});
+
     my $uri;
 
     my $req = Jifty->web->request;
@@ -135,29 +138,30 @@ sub url {
         $uri->path_query('/');
     }
     else {
-        $uri = URI->new(Jifty->config->framework("Web")->{BaseURL});
-        $uri->port(Jifty->config->framework("Web")->{Port});
-    }
-
-    if (defined (my $path = $args{path})) {
-        # strip off leading '/' because ->canonical provides one
-        $path =~ s{^/}{};
-        $uri->path_query($path);
+        $uri = $base_uri->clone;
     }
 
     # https is sticky
     $uri->scheme('https') if $uri->scheme eq 'http' && Jifty->web->is_ssl;
 
-    # If we're generating a URL from an email (really a Jifty::Notification
-    # subclass), default to http
+    # If we're generating a URL for an email (really a Jifty::Notification
+    # subclass), force the app's configured URL rather than relying on the
+    # irrelevant current request.
     my $level = 0;
     while ( my $class = caller($level++) ) {
         if ( $class->isa("Jifty::Notification") ) {
-            $uri->scheme('http');
+            $uri = $base_uri->clone;
             last;
         }
     }
 
+    # Always set path and scheme if they're passed explicitly
+    if (defined (my $path = $args{path})) {
+        # strip off leading '/' because ->canonical provides one
+        $path =~ s{^/}{};
+        $uri->path_query($path);
+    }
+
     $uri->scheme( $args{'scheme'} ) if defined $args{'scheme'};
 
     return $uri->canonical->as_string;

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


More information about the Jifty-commit mailing list