I am thinking about something like the below:

Index: server/core.c
===================================================================
--- server/core.c       (revision 344120)
+++ server/core.c       (working copy)
@@ -115,6 +115,7 @@
     conf->accept_path_info = 3;
     conf->use_canonical_name = USE_CANONICAL_NAME_UNSET;
+    conf->use_canonical_phys_port = USE_CANONICAL_PHYS_PORT_UNSET;
     conf->hostname_lookups = HOSTNAME_LOOKUP_UNSET;
     conf->satisfy = apr_palloc(a, sizeof(*conf->satisfy) * METHODS);
@@ -315,6 +316,10 @@
         conf->use_canonical_name = new->use_canonical_name;
     }
+ if (new->use_canonical_phys_port != USE_CANONICAL_PHYS_PORT_UNSET) {
+        conf->use_canonical_phys_port = new->use_canonical_phys_port;
+    }
+
#ifdef RLIMIT_CPU
     if (new->limit_cpu) {
         conf->limit_cpu = new->limit_cpu;
@@ -959,10 +964,15 @@
          * URLs using the hostname and port supplied by the client if
* any are supplied (otherwise it will use the canonical name).
          */
-        port = r->parsed_uri.port_str ? r->parsed_uri.port :
- r->connection->local_addr->port ? r->connection- >local_addr->port :
-               r->server->port ? r->server->port :
-               ap_default_port(r);
+        if (d->use_canonical_phys_port == USE_CANONICAL_PHYS_PORT_ON)
+            port = r->parsed_uri.port_str ? r->parsed_uri.port :
+ r->connection->local_addr->port ? r->connection- >local_addr->port :
+                   r->server->port ? r->server->port :
+                   ap_default_port(r);
+        else
+            port = r->parsed_uri.port_str ? r->parsed_uri.port :
+                   r->server->port ? r->server->port :
+                   ap_default_port(r);
     }
     else { /* d->use_canonical_name == USE_CANONICAL_NAME_ON */
@@ -974,9 +984,13 @@
* any is supplied, and finally the default port for the protocol
          * used.
          */
-        port = r->server->port ? r->server->port :
- r->connection->local_addr->port ? r->connection- >local_addr->port :
-               ap_default_port(r);
+        if (d->use_canonical_phys_port == USE_CANONICAL_PHYS_PORT_ON)
+            port = r->server->port ? r->server->port :
+ r->connection->local_addr->port ? r->connection- >local_addr->port :
+                   ap_default_port(r);
+        else
+            port = r->server->port ? r->server->port :
+                   ap_default_port(r);
     }
     /* default */
@@ -2484,7 +2498,30 @@
     return NULL;
}
+static const char *set_use_canonical_phys_port(cmd_parms *cmd, void *d_,
+                                          const char *arg)
+{
+    core_dir_config *d = d_;
+    const char *err = ap_check_cmd_context(cmd, NOT_IN_LIMIT);
+    if (err != NULL) {
+        return err;
+    }
+
+    if (strcasecmp(arg, "on") == 0) {
+        d->use_canonical_phys_port = USE_CANONICAL_PHYS_PORT_ON;
+    }
+    else if (strcasecmp(arg, "off") == 0) {
+        d->use_canonical_phys_port = USE_CANONICAL_PHYS_PORT_OFF;
+    }
+    else {
+        return "parameter must be 'on' or 'off'";
+    }
+
+    return NULL;
+}
+
+
static const char *include_config (cmd_parms *cmd, void *dummy,
                                    const char *name)
{
@@ -3259,6 +3296,9 @@
AP_INIT_TAKE1("UseCanonicalName", set_use_canonical_name, NULL,
   RSRC_CONF|ACCESS_CONF,
   "How to work out the ServerName : Port when constructing URLs"),
+AP_INIT_TAKE1("UseCanonicalPhysicalPort", set_use_canonical_phys_port, NULL,
+  RSRC_CONF|ACCESS_CONF,
+  "Whether to use the physical Port when constructing URLs"),
/* TODO: RlimitFoo should all be part of mod_cgi, not in the core */
/* TODO: ListenBacklog in MPM */
AP_INIT_TAKE1("Include", include_config, NULL,
Index: include/http_core.h
===================================================================
--- include/http_core.h (revision 344120)
+++ include/http_core.h (working copy)
@@ -482,6 +482,11 @@
#define USE_CANONICAL_NAME_UNSET (3)
     unsigned use_canonical_name : 2;
+#define USE_CANONICAL_PHYS_PORT_OFF   (0)
+#define USE_CANONICAL_PHYS_PORT_ON    (1)
+#define USE_CANONICAL_PHYS_PORT_UNSET (2)
+    unsigned use_canonical_phys_port : 2;
+
     /* since is_fnmatch(conf->d) was being called so frequently in
      * directory_walk() and its relatives, this field was created and
      * is set to the result of that call.

Reply via email to