Include smart http:// URLs in gitweb

Since we support smart HTTP, we should advertise it on the project
summary pages within our managed gitweb instance.  Like with
the ssh:// protocol URLs, we insert the current username if
authentication is required to access the project.

Change-Id: I2568a930b78d8987c82ef59e4fcdd908a512427e
Signed-off-by: Shawn O. Pearce <sop@google.com>
diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/gitweb/GitWebServlet.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/gitweb/GitWebServlet.java
index abcc642..3a1f2b62 100644
--- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/gitweb/GitWebServlet.java
+++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/gitweb/GitWebServlet.java
@@ -175,8 +175,23 @@
       //
       p.print("$prevent_xss = 1;\n");
 
-      // Generate URLs using the anonymous git:// and secured ssh:// scheme,
-      // this matches the pull URLs we publish on each change screen.
+      // Generate URLs using smart http://
+      //
+      p.print("{\n");
+      p.print("  my $secure = $ENV{'HTTPS'} =~ /^ON$/i;\n");
+      p.print("  my $http_url = $secure ? 'https://' : 'http://';\n");
+      p.print("  $http_url .= qq{$ENV{'GERRIT_USER_NAME'}@}\n");
+      p.print("    unless $ENV{'GERRIT_ANONYMOUS_READ'};\n");
+      p.print("  $http_url .= $ENV{'SERVER_NAME'};\n");
+      p.print("  $http_url .= qq{:$ENV{'SERVER_PORT'}}\n");
+      p.print("    if (( $secure && $ENV{'SERVER_PORT'} != 443)\n");
+      p.print("     || (!$secure && $ENV{'SERVER_PORT'} != 80)\n");
+      p.print("    );\n");
+      p.print("  $http_url .= qq{$ENV{'GERRIT_CONTEXT_PATH'}p};\n");
+      p.print("  push @git_base_url_list, $http_url;\n");
+      p.print("}\n");
+
+      // Generate URLs using anonymous git://
       //
       if (gerritConfig.getGitDaemonUrl() != null) {
         String url = gerritConfig.getGitDaemonUrl();
@@ -189,6 +204,9 @@
         p.print(";\n");
         p.print("}\n");
       }
+
+      // Generate URLs using authenticated ssh://
+      //
       if (gerritConfig.getSshdAddress() != null) {
         String sshAddr = gerritConfig.getSshdAddress();
         p.print("if ($ENV{'GERRIT_USER_NAME'}) {\n");