You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Brian Akins <ba...@web.turner.com> on 2005/11/11 21:33:33 UTC

ap_get_server_port differences

in 2.1.9 ap_get_server_port uses the following:

  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);


in 2.0.55 it uses:

  port = r->parsed_uri.port_str ? r->parsed_uri.port :
                r->server->port ? r->server->port :
                ap_default_port(r);


This just bit me bad!  I was used to being able to declare things like:

ServerName www.domain.com:80

and having redirects (mod_dir, etc) to pick up on this via ap_construct_url


What, if any, is the work around for 2.1.9?  I really don't want to use 
"UseCanonicalName On"




-- 
Brian Akins
Lead Systems Engineer
CNN Internet Technologies

Re: ap_get_server_port differences

Posted by Paul Querna <ch...@force-elite.com>.
Sander Temme wrote:
......
> Did you force it to 'Off' in 2.0? If you have it 'Off', you believe what
> the client sends you, or what you explicitly stashed in the server
> record by specifying it in the ServerName directive. In the newer
> server, we added the actual port the request came in on, which should
> match the information in the server_rec...
> 
> In the other case, UseCanonicalName On which was default in the 2.0
> branch, we look first in the server_rec and then in the connection. You
> could possibly make a case for having the search order in the top of the
> if clause match the one in the bottom. This against trunk:
> 
> ===================================================================
> --- server/core.c       (revision 332799)
> +++ server/core.c       (working copy)
> @@ -960,8 +960,8 @@
>           * any are supplied (otherwise it will use the canonical name).
>           */
>          port = r->parsed_uri.port_str ? r->parsed_uri.port :
> +               r->server->port ? r->server->port :
>                 r->connection->local_addr->port ?
> r->connection->local_addr->port :
> -               r->server->port ? r->server->port :
>                 ap_default_port(r);
>      }
>      else { /* d->use_canonical_name == USE_CANONICAL_NAME_ON */
> 
> That would probably better align with the principle of least astonishment.
> 

+1 to the above.

-Paul


Re: ap_get_server_port differences

Posted by Brian Akins <ba...@web.turner.com>.
Sander Temme wrote:
> 
> On Nov 11, 2005, at 12:33 PM, Brian Akins wrote:
> 
>> in 2.1.9 ap_get_server_port uses the following:
>>
>>  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);
>>
>>
>> in 2.0.55 it uses:
>>
>>  port = r->parsed_uri.port_str ? r->parsed_uri.port :
>>                r->server->port ? r->server->port :
>>                ap_default_port(r);
>>
>>
>> This just bit me bad!  I was used to being able to declare things  like:
> 
> 
> What bit you is probably the change in default value for  
> UseCanonicalName? Used to be On by default, now it's Off. Try  flicking 
> that switch.
> 
>> ServerName www.domain.com:80
>>
>> and having redirects (mod_dir, etc) to pick up on this via  
>> ap_construct_url
>>
>>
>> What, if any, is the work around for 2.1.9?  I really don't want to  
>> use "UseCanonicalName On"
> 
> 
> Did you force it to 'Off' in 2.0? 


Yes.

> If you have it 'Off', you believe  
> what the client sends you, or what you explicitly stashed in the  server 
> record by specifying it in the ServerName directive.


I would "stash" it in Servername.


> ===================================================================
> --- server/core.c       (revision 332799)
> +++ server/core.c       (working copy)
> @@ -960,8 +960,8 @@
>           * any are supplied (otherwise it will use the canonical  name).
>           */
>          port = r->parsed_uri.port_str ? r->parsed_uri.port :
> +               r->server->port ? r->server->port :
>                 r->connection->local_addr->port ? r->connection- 
>  >local_addr->port :
> -               r->server->port ? r->server->port :
>                 ap_default_port(r);
>      }
>      else { /* d->use_canonical_name == USE_CANONICAL_NAME_ON */
> 


I think that would work for me.  If clients. set bogus ports, they get 
what they deserve.


+1 if that matters.

Any possibility of this being in 2.1.10 (or 2.2-rc1/2 whatever we are 
calling next "pre-release.")




-- 
Brian Akins
Lead Systems Engineer
CNN Internet Technologies

Re: ap_get_server_port differences

Posted by Sander Temme <sc...@apache.org>.
On Nov 11, 2005, at 12:33 PM, Brian Akins wrote:

> in 2.1.9 ap_get_server_port uses the following:
>
>  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);
>
>
> in 2.0.55 it uses:
>
>  port = r->parsed_uri.port_str ? r->parsed_uri.port :
>                r->server->port ? r->server->port :
>                ap_default_port(r);
>
>
> This just bit me bad!  I was used to being able to declare things  
> like:

What bit you is probably the change in default value for  
UseCanonicalName? Used to be On by default, now it's Off. Try  
flicking that switch.

> ServerName www.domain.com:80
>
> and having redirects (mod_dir, etc) to pick up on this via  
> ap_construct_url
>
>
> What, if any, is the work around for 2.1.9?  I really don't want to  
> use "UseCanonicalName On"

Did you force it to 'Off' in 2.0? If you have it 'Off', you believe  
what the client sends you, or what you explicitly stashed in the  
server record by specifying it in the ServerName directive. In the  
newer server, we added the actual port the request came in on, which  
should match the information in the server_rec...

In the other case, UseCanonicalName On which was default in the 2.0  
branch, we look first in the server_rec and then in the connection.  
You could possibly make a case for having the search order in the top  
of the if clause match the one in the bottom. This against trunk:

===================================================================
--- server/core.c       (revision 332799)
+++ server/core.c       (working copy)
@@ -960,8 +960,8 @@
           * any are supplied (otherwise it will use the canonical  
name).
           */
          port = r->parsed_uri.port_str ? r->parsed_uri.port :
+               r->server->port ? r->server->port :
                 r->connection->local_addr->port ? r->connection- 
 >local_addr->port :
-               r->server->port ? r->server->port :
                 ap_default_port(r);
      }
      else { /* d->use_canonical_name == USE_CANONICAL_NAME_ON */

That would probably better align with the principle of least  
astonishment.

S.

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


Re: ap_get_server_port differences

Posted by Ruediger Pluem <rp...@apache.org>.

On 11/12/2005 06:46 PM, Sander Temme wrote:

[..cut..]

> 
> What bit you is probably the change in default value for 
> UseCanonicalName? Used to be On by default, now it's Off. Try  flicking
> that switch.

I saw that it is now set to off in the default configuration files, but the
behaviour of the code confuses me if it is not set at all in the configuration.
In this case use_canonical_name is set to USE_CANONICAL_NAME_UNSET, but:

In ap_get_server_name the behaviour in this case is like OFF and

    if (d->use_canonical_name == USE_CANONICAL_NAME_ON) {
        return r->server->server_hostname;
    }

    if (d->use_canonical_name == USE_CANONICAL_NAME_DNS) {
        if (conn->local_host == NULL) {
            if (apr_getnameinfo(&conn->local_host,
                                conn->local_addr, 0) != APR_SUCCESS)
                conn->local_host = apr_pstrdup(conn->pool,
                                               r->server->server_hostname);
            else {
                ap_str_tolower(conn->local_host);
            }
        }

        return conn->local_host;
    }

in ap_get_server_port it is like ON:


   if (d->use_canonical_name == USE_CANONICAL_NAME_OFF
        || d->use_canonical_name == USE_CANONICAL_NAME_DNS) {

        /* With UseCanonicalName off Apache will form self-referential
         * 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);
    }
    else { /* d->use_canonical_name == USE_CANONICAL_NAME_ON */

Is this correct?


Regards

RĂ¼diger

[..cut..]

Re: ap_get_server_port differences

Posted by Sander Temme <sa...@temme.net>.
On Nov 11, 2005, at 12:33 PM, Brian Akins wrote:

> in 2.1.9 ap_get_server_port uses the following:
>
>  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);
>
>
> in 2.0.55 it uses:
>
>  port = r->parsed_uri.port_str ? r->parsed_uri.port :
>                r->server->port ? r->server->port :
>                ap_default_port(r);
>
>
> This just bit me bad!  I was used to being able to declare things  
> like:

What bit you is probably the change in default value for  
UseCanonicalName? Used to be On by default, now it's Off. Try  
flicking that switch.

> ServerName www.domain.com:80
>
> and having redirects (mod_dir, etc) to pick up on this via  
> ap_construct_url
>
>
> What, if any, is the work around for 2.1.9?  I really don't want to  
> use "UseCanonicalName On"

Did you force it to 'Off' in 2.0? If you have it 'Off', you believe  
what the client sends you, or what you explicitly stashed in the  
server record by specifying it in the ServerName directive. In the  
newer server, we added the actual port the request came in on, which  
should match the information in the server_rec...

In the other case, UseCanonicalName On which was default in the 2.0  
branch, we look first in the server_rec and then in the connection.  
You could possibly make a case for having the search order in the top  
of the if clause match the one in the bottom. This against trunk:

===================================================================
--- server/core.c       (revision 332799)
+++ server/core.c       (working copy)
@@ -960,8 +960,8 @@
           * any are supplied (otherwise it will use the canonical  
name).
           */
          port = r->parsed_uri.port_str ? r->parsed_uri.port :
+               r->server->port ? r->server->port :
                 r->connection->local_addr->port ? r->connection- 
 >local_addr->port :
-               r->server->port ? r->server->port :
                 ap_default_port(r);
      }
      else { /* d->use_canonical_name == USE_CANONICAL_NAME_ON */

That would probably better align with the principle of least  
astonishment.

S.

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


Re: ap_get_server_port differences

Posted by Brian Akins <br...@turner.com>.
Here's the quick workaround module.  Just load the modules and it tries 
to "revert" to 2.0 behavior

#include "httpd.h"
#include "http_config.h"
#include "ap_config.h"
#include "apr_strings.h"
#include "http_protocol.h"

module AP_MODULE_DECLARE_DATA port_module;

typedef struct {
     apr_port_t port;
     char *port_str;
} port_config;


static int port(request_rec *r)
{
     port_config *conf;

     if((conf = ap_get_module_config(r->server->module_config, 
&port_module)) != NULL) {
         if(conf->port_str) {
             /*looking at server/core.c, ap_get_server_port This looks 
to be the best place
              * UseCanonicalName MUST be off, or this is ignored*/
             r->parsed_uri.port     = conf->port;
             r->parsed_uri.port_str = conf->port_str;
         }
     }

     return DECLINED;
}

static int post_config(apr_pool_t * pconf, apr_pool_t * plog,
                   apr_pool_t * ptemp, server_rec *s)
{
     server_rec *virt;
     port_config *port;

     for(virt = s; virt; virt = virt->next) {
         port = apr_pcalloc(pconf, sizeof(port_config));
         if(virt->port) {
             port->port = virt->port;
             port->port_str = apr_psprintf(pconf, "%u", virt->port);
             ap_set_module_config(virt->module_config, &port_module, port);
         }

     }

     return OK;
}

static void register_hooks(apr_pool_t * p)
{
     ap_hook_post_read_request(port, NULL, NULL, APR_HOOK_REALLY_FIRST);
     ap_hook_post_config(post_config, NULL, NULL, APR_HOOK_MIDDLE);
}

/* Dispatch list for API hooks */
module AP_MODULE_DECLARE_DATA port_module = {
     STANDARD20_MODULE_STUFF,
     NULL,       /* create per-dir    config structures */
     NULL,        /* merge  per-dir    config structures */
     NULL,   /* create per-server config structures */
     NULL,                       /* merge  per-server config structures */
     NULL,            /* table of config file commands       */
     register_hooks   /* register hooks                      */
};


-- 
Brian Akins
Lead Systems Engineer
CNN Internet Technologies