[Moin-user] port disappears on certain urls -> non-default port, HTTP_HOST = varying
Joshua Rodman
joshua_rodman at yahoo.com
Tue Mar 4 00:36:10 EST 2003
I have a possibly unusual config.
I'm running thttpd, and have told it to respond to whatever
server name it happens to receive.
Thus, http://myserver.mydomain.com works, as does http://localhost
(in the right circumstances).
I've got it running on a nonstandard port though, so the following
are the real urls: http://myserver.mydomain.com:81, http://localhost:81
HTTP_HOST gets sent as myserver.mydomain.com and localhost, respectively,
which appears to be acceptable for the HTTP standard, despite
the nonstandard port number.
SERVER_NAME is set to 'myserver', which may be wrong, but I believe
is not relevant.
SERVER_PORT is set to '81'.
Some urls, like a few involving the AttachFile feature, make use
of the getBaseURL and/or getQualifiedURL methods in the webapi
module. On my system this interface returns urls like:
http://myserver.mydomain.com/blahblah/
or
http://localhost/blahblah/
Since these head back to port 80, they don't work.
The relvant code in getQualifiedURL is as follows:
def getQualifiedURL(uri = None):
[...]
schema, stdport = (('http', '80'), ('https', '443'))[isSSL()]
host = os.environ.get('HTTP_HOST')
if not host:
host = os.environ.get('SERVER_NAME', 'localhost')
port = os.environ.get('SERVER_PORT', '80')
if port != stdport: host = host + ":" + port
result = "%s://%s" % (schema, host)
[...]
Since HTTP_HOST is set, this code will return
SCHEMA://HTTP_HOST/uri
eg http://localhost/blahblah
it seems a correct implementation must test HTTP_HOST to see if a
port specification was given (a colon followed by the port data), and
add the :SERVER_PORT if it is not present, in order to maintain
connectivity.
My quick and possibly incorrect hack was:
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
port = os.environ.get('SERVER_PORT', '80')
if port != stdport: host = host + ":" + port
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
if not ':' in host:
port = os.environ.get('SERVER_PORT', '80')
if port != stdport: host = host + ":" + port
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-josh
__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/
More information about the Moin-user
mailing list