httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sander Temme <scte...@apache.org>
Subject [PATCH] Re: [PATCH] Support for external listener
Date Thu, 20 Apr 2006 22:22:10 GMT

On Mar 20, 2006, at 11:50 PM, Sander Temme wrote:

>>> ExternalListenerScheme http|https
>>
>> perhaps servername shoudl be defined like:
>>
>> ServerName https://www.example.com:443
>> UseCanonicalScheme On
>
> I like this. It's, like, three configuration values for the price  
> of one directive.


The following patch implements the

ServerName [scheme://]hostname[:port]

idea. The directive accepts anything for scheme, but the http module  
returns "http" for scheme and DEFAULT_HTTP_PORT for anything but  
"https" in the server_rec->server_scheme field. It may be useful for  
other modules to be able to return different values, but right now it  
needs to return "http" as default scheme to maintain backwards  
compatibility. The below is completely backwards compatible and  
passes the perl-framework testsuite as well as the unmodified trunk.

This patch not only does the right thing regarding directory-without- 
trailing-slash redirects, but it also makes Subversion mv and cp work  
behind both a httpd proxy and the SSL offload card my company makes.

I'm adding the server_scheme to the server_rec, which I believe to  
cause a minor MMN bump. I initially tried to co-opt the protocol  
field in the core_server_config, but ran into issues where mod_ssl  
will keep the server from starting if prototol == https but SSL is  
not enabled. That is exactly what I'm trying to subvert here.  
Additionally, it may be good to separate network software  
configuration (Listen, Protocol, ListenBacklog, ...) from the  
logistics like ServerName, server_rec->port and now server_rec- 
 >server_scheme.

Comments? Objections?

S.

Index: server/config.c
===================================================================
--- server/config.c     (revision 395280)
+++ server/config.c     (working copy)
@@ -1855,6 +1855,7 @@
      s->process = main_server->process;
      s->server_admin = NULL;
      s->server_hostname = NULL;
+    s->server_scheme = NULL;
      s->error_fname = NULL;
      s->timeout = 0;
      s->keep_alive_timeout = 0;
@@ -1940,6 +1941,7 @@
      s->port = 0;
      s->server_admin = DEFAULT_ADMIN;
      s->server_hostname = NULL;
+    s->server_scheme = NULL;
      s->error_fname = DEFAULT_ERRORLOG;
      s->loglevel = DEFAULT_LOGLEVEL;
      s->limit_req_line = DEFAULT_LIMIT_REQUEST_LINE;
Index: server/core.c
===================================================================
--- server/core.c       (revision 395280)
+++ server/core.c       (working copy)
@@ -2225,20 +2225,41 @@
      return NULL;
}
+/*
+ * The ServerName directive takes one argument with format
+ * [scheme://]fully-qualified-domain-name[:port], for instance
+ * ServerName www.example.com
+ * ServerName www.example.com:80
+ * ServerName https://www.example.com:443
+ */
+
static const char *server_hostname_port(cmd_parms *cmd, void *dummy,  
const char *arg)
{
      const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE| 
NOT_IN_LIMIT);
-    const char *portstr;
+    core_server_config *conf;
+    const char *portstr, *part;
+    char *scheme;
      int port;
      if (err != NULL) {
          return err;
      }
-    portstr = ap_strchr_c(arg, ':');
+    part = ap_strstr_c(arg, "://");
+
+    if (part) {
+      scheme = apr_pstrndup(cmd->pool, arg, part - arg);
+      ap_str_tolower(scheme);
+      cmd->server->server_scheme = (const char *)scheme;
+      part += 3;
+    } else {
+      part = arg;
+    }
+
+    portstr = ap_strchr_c(part, ':');
      if (portstr) {
-        cmd->server->server_hostname = apr_pstrndup(cmd->pool, arg,
-                                                    portstr - arg);
+        cmd->server->server_hostname = apr_pstrndup(cmd->pool, part,
+                                                    portstr - part);
          portstr++;
          port = atoi(portstr);
          if (port <= 0 || port >= 65536) { /* 65536 == 1<<16 */
@@ -2248,7 +2269,7 @@
          }
      }
      else {
-        cmd->server->server_hostname = apr_pstrdup(cmd->pool, arg);
+        cmd->server->server_hostname = apr_pstrdup(cmd->pool, part);
          port = 0;
      }
Index: modules/http/http_core.c
===================================================================
--- modules/http/http_core.c    (revision 395280)
+++ modules/http/http_core.c    (working copy)
@@ -99,11 +99,23 @@
static const char *http_scheme(const request_rec *r)
{
+    /*
+     * The http module shouldn't return anything other than
+     * "http" (the default) or "https".
+     */
+    if (r->server->server_scheme &&
+        (strcmp(r->server->server_scheme, "https") == 0))
+        return "https";
+
      return "http";
}
static apr_port_t http_port(const request_rec *r)
{
+    if (r->server->server_scheme &&
+        (strcmp(r->server->server_scheme, "https") == 0))
+        return DEFAULT_HTTPS_PORT;
+
      return DEFAULT_HTTP_PORT;
}
Index: include/ap_mmn.h
===================================================================
--- include/ap_mmn.h    (revision 395280)
+++ include/ap_mmn.h    (working copy)
@@ -120,6 +120,7 @@
   * 20060110.2 (2.3.0-dev)  flush_packets and flush_wait members  
added to
   *                         proxy_server (minor)
   * 20060110.3 (2.3.0-dev)  added inreslist member to proxy_conn_rec  
(minor)
+ * 20060110.4 (2.3.0-dev)  Added server_scheme member to server_rec  
(minor)
   */
#define MODULE_MAGIC_COOKIE 0x41503234UL /* "AP24" */
@@ -127,7 +128,7 @@
#ifndef MODULE_MAGIC_NUMBER_MAJOR
#define MODULE_MAGIC_NUMBER_MAJOR 20060110
#endif
-#define MODULE_MAGIC_NUMBER_MINOR 3                     /* 0...n */
+#define MODULE_MAGIC_NUMBER_MINOR 4                     /* 0...n */
/**
   * Determine if the server's current MODULE_MAGIC_NUMBER is at least a
Index: include/httpd.h
===================================================================
--- include/httpd.h     (revision 395280)
+++ include/httpd.h     (working copy)
@@ -1197,6 +1197,9 @@
      int limit_req_fieldsize;
      /** limit on number of request header fields  */
      int limit_req_fields;
+
+    /** The server request scheme for redirect responses */
+    const char *server_scheme;
};
typedef struct core_output_filter_ctx {

-- 
sander@temme.net              http://www.temme.net/sander/
PGP FP: 51B4 8727 466A 0BC3 69F4  B7B8 B2BE BC40 1529 24AF


Mime
View raw message