tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject git commit: TAP5-1973: In certain development cases when switching from insecure to secure, BaseURLSource will still include :443 in the URL
Date Fri, 01 Aug 2014 23:54:02 GMT
Repository: tapestry-5
Updated Branches:
  refs/heads/master a29d1ea93 -> 30a66c952


TAP5-1973: In certain development cases when switching from insecure to secure, BaseURLSource
will still include :443 in the URL


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/30a66c95
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/30a66c95
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/30a66c95

Branch: refs/heads/master
Commit: 30a66c9526dee3da55a5204e43a169fe4692df79
Parents: a29d1ea
Author: Howard M. Lewis Ship <hlship@apache.org>
Authored: Fri Aug 1 16:54:06 2014 -0700
Committer: Howard M. Lewis Ship <hlship@apache.org>
Committed: Fri Aug 1 16:54:06 2014 -0700

----------------------------------------------------------------------
 .../internal/services/BaseURLSourceImpl.java    | 12 +++++------
 .../services/BaseURLSourceImplTest.java         | 21 ++++++++++++++++++--
 2 files changed, 24 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/30a66c95/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/BaseURLSourceImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/BaseURLSourceImpl.java
b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/BaseURLSourceImpl.java
index b7ea719..11b6bd8 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/BaseURLSourceImpl.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/BaseURLSourceImpl.java
@@ -1,5 +1,3 @@
-// Copyright 2008, 2010, 2011, 2012 The Apache Software Foundation
-//
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
 // You may obtain a copy of the License at
@@ -48,23 +46,23 @@ public class BaseURLSourceImpl implements BaseURLSource
 
     private String portExtension(boolean secure)
     {
-        int port = secure ? secureHostPort : hostPort;
+        int configuredPort = secure ? secureHostPort : hostPort;
 
         // The default for the ports is 0, which means to use Request.serverPort. That's
mostly
         // for development.
-        if (port <= 0)
+        if (configuredPort <= 0 && secure == request.isSecure())
         {
-            port = request.getServerPort();
+            configuredPort = request.getServerPort();
         }
 
         int expectedPort = secure ? 443 : 80;
 
-        if (port == expectedPort)
+        if (configuredPort == expectedPort || configuredPort <= 0)
         {
             return "";
         }
 
-        return ":" + port;
+        return ":" + configuredPort;
     }
 
     private String hostname()

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/30a66c95/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/BaseURLSourceImplTest.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/BaseURLSourceImplTest.java
b/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/BaseURLSourceImplTest.java
index 5dc4f89..31edf38 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/BaseURLSourceImplTest.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/BaseURLSourceImplTest.java
@@ -1,5 +1,3 @@
-// Copyright 2008, 2010, 2011, 2012 The Apache Software Foundation
-//
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
 // You may obtain a copy of the License at
@@ -36,6 +34,7 @@ public class BaseURLSourceImplTest extends InternalBaseTestCase
     {
         expect(request.getServerName()).andReturn("localhost").once();
         expect(request.getServerPort()).andReturn(80).once();
+        expect(request.isSecure()).andReturn(false);
 
         replay();
 
@@ -49,6 +48,7 @@ public class BaseURLSourceImplTest extends InternalBaseTestCase
     public void contributed_hostname()
     {
         expect(request.getServerPort()).andReturn(80).once();
+        expect(request.isSecure()).andReturn(false);
 
         replay();
 
@@ -63,6 +63,7 @@ public class BaseURLSourceImplTest extends InternalBaseTestCase
     public void hostname_from_environment_variable()
     {
         expect(request.getServerPort()).andReturn(80).once();
+        expect(request.isSecure()).andReturn(false);
 
         replay();
 
@@ -109,4 +110,20 @@ public class BaseURLSourceImplTest extends InternalBaseTestCase
         verify();
     }
 
+    @Test
+    public void secure_url_without_configured_hostports()
+    {
+        expect(request.isSecure()).andReturn(false).once();
+
+        replay();
+
+        BaseURLSource baseURLSource = new BaseURLSourceImpl(request, "localhost", 0, 0);
+
+        // In other words, in the absense of any other configuration, it assumes that you
have SSL on port 443
+        // and there's no need for that in the URL, since that's what the browser is going
to do.
+        assertEquals(baseURLSource.getBaseURL(true), "https://localhost");
+
+        verify();
+    }
+
 }


Mime
View raw message