You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Lars Oppermann <la...@germany.sun.com> on 2001/02/19 17:59:17 UTC

Incorrect behaviour in ap_get_server_port()?

Hi everybody,

I am working as a software engineer for Sun Microsystems in Hamburg,
Germany. We are currently developing a web based application framework
that should be integratable with the apache webserver. Most application
layer functionality is implemented via java servlets. (We are currently
using Tomcat for that part)

In this framework, there is an application which distributes http
requests among several webservers. (in my case, those webserver are
Apache 1.3.xx connected via mod_jk/ajp13 to one or more Tomcat servlet
containers.) 

Now, whenever a self-referencing, absolute URL is to be constructed, it
has to point to said application responsible for request distribution,
and not to the particular Apache server that generated the response
containing this URL. To achive this, we set the 'Host:' header in the
request sent from the distributing application to the Apache server
accordingly. This does indeed work for hostnames, but not for
Portnumbers (UseCanonicalName is turned off in Apache).

Looking at the code of both mod_jk and Apache, I found that as far as
the Host header field is concerned, when use_canonical_name is
USE_CANONICAL_NAME_OFF or USE_CANONICAL_NAME_DNS and a host header was
supplied, the function will return the port-number, the client actualy
connected to, not the one specified in the host header as one would
expect from the documentation of UseCanonicalName.

It might be that I'm simply not getting something here, so please
correct me if I'm wrong. Otherwise I'd like to know if you are intersted
in a patch and to whom it should be sent.

(Mod_jk also does not handle the port correctly, but that is not to the
concern of this group, I think),

Bests,
Lars 
-- 
----------------------------------------------------------------------
Lars Oppermann                                        Sun Microsystems
Software Engineer                                      Staroffice GmbH  
Phone: +49 40 23646 959                                  Sachsenfeld 4
Fax:   +49 40 23646 550                                D-20097 Hamburg
lars.oppermann@germany.sun.com           http://www.sun.com/staroffice
----------------------------------------------------------------------

Re: Incorrect behaviour in ap_get_server_port()?

Posted by Lars Oppermann <la...@germany.sun.com>.
Tony Finch wrote:
> 
> Lars Oppermann <la...@germany.sun.com> wrote:
> >
> >Now, whenever a self-referencing, absolute URL is to be constructed, it
> >has to point to said application responsible for request distribution,
> >and not to the particular Apache server that generated the response
> >containing this URL. To achive this, we set the 'Host:' header in the
> >request sent from the distributing application to the Apache server
> >accordingly. This does indeed work for hostnames, but not for
> >Portnumbers (UseCanonicalName is turned off in Apache).
> 
> Gosh, this is becoming a *very* frequently asked question. I'm not
> sure where we can improve the documentation to make it clearer, though.
> 
> Use the "Listen" directive to configure the port that Apache listens
> on, and use the "Port" directive to configure the port that Apache
> uses to refer to itself.
> 

This is true, as long as the value for the 'Port' directive can be
determined before apache is started and is the same for all entrypoints
that relay requests to the apache server.

However I am of the opinion that the content of the Host header supplied
by the client should be used when UseCanonicalNames is turned off. I
don't think that the current behaviour of using the portnumber through
which the connection was made whenever a host header is present
(hostname in the request_rec is set) or else fall back to the value of
the Port directive is realy the right way to handle this.

What do you think?

Greetings,
Lars
-- 
----------------------------------------------------------------------
Lars Oppermann                                        Sun Microsystems
Software Engineer                                      Staroffice GmbH  
Phone: +49 40 23646 959                                  Sachsenfeld 4
Fax:   +49 40 23646 550                                D-20097 Hamburg
lars.oppermann@germany.sun.com           http://www.sun.com/staroffice
----------------------------------------------------------------------

Re: Incorrect behaviour in ap_get_server_port()?

Posted by Tony Finch <do...@dotat.at>.
Lars Oppermann <la...@germany.sun.com> wrote:
>
>Now, whenever a self-referencing, absolute URL is to be constructed, it
>has to point to said application responsible for request distribution,
>and not to the particular Apache server that generated the response
>containing this URL. To achive this, we set the 'Host:' header in the
>request sent from the distributing application to the Apache server
>accordingly. This does indeed work for hostnames, but not for
>Portnumbers (UseCanonicalName is turned off in Apache).

Gosh, this is becoming a *very* frequently asked question. I'm not
sure where we can improve the documentation to make it clearer, though.

Use the "Listen" directive to configure the port that Apache listens
on, and use the "Port" directive to configure the port that Apache
uses to refer to itself.

e.g. with
	Listen 8000
	Port 80
Apache accepts requests on port 8000 but when generating redirects or
other self-referential URLs it uses port 80. This is designed to work
in exactly your situation.

Tony.
-- 
f.a.n.finch    fanf@covalent.net    dot@dotat.at
VIKING NORTH UTSIRE SOUTH UTSIRE: WEST OR NORTHWEST 5 INCREASING 6 OR 7. RAIN
THEN SHOWERS. MODERATE OR GOOD.

Re: Incorrect behaviour in ap_get_server_port()?

Posted by Tony Finch <do...@dotat.at>.
Lars Oppermann <la...@germany.sun.com> wrote:
>
>Now, whenever a self-referencing, absolute URL is to be constructed, it
>has to point to said application responsible for request distribution,
>and not to the particular Apache server that generated the response
>containing this URL. To achive this, we set the 'Host:' header in the
>request sent from the distributing application to the Apache server
>accordingly. This does indeed work for hostnames, but not for
>Portnumbers (UseCanonicalName is turned off in Apache).

Gosh, this is becoming a *very* frequently asked question. I'm not
sure where we can improve the documentation to make it clearer, though.

Use the "Listen" directive to configure the port that Apache listens
on, and use the "Port" directive to configure the port that Apache
uses to refer to itself.

e.g. with
	Listen 8000
	Port 80
Apache accepts requests on port 8000 but when generating redirects or
other self-referential URLs it uses port 80. This is designed to work
in exactly your situation.

Tony.
-- 
f.a.n.finch    fanf@covalent.net    dot@dotat.at
VIKING NORTH UTSIRE SOUTH UTSIRE: WEST OR NORTHWEST 5 INCREASING 6 OR 7. RAIN
THEN SHOWERS. MODERATE OR GOOD.