Ross,

>>I think this is a case of thttpd not setting up the HTTP_HOST 
>>environment variable correctly....  I'm guessing thttpd omits 
>>the port number.
> 
> Yes, it does, from the HTTP_HOST variable at least.
> 
>>   That would be a mistake on the part of thttpd, if I'm not 
>> badly mistaken.
> 
> I'm having trouble finding a definitive answer to that question. 
> The various copies of "CGI 1.1" documentation I've found are 
> either silent about variables named HTTP_*, or suggest that they 
> are derived from the HTTP request header in an underspecified 
> way. I'd tend to agree that whatever Apache does is probably the 
> "most correct" however.

The CGI protocol specifies that all http headers of the request are passed
on to the cgi script as environment variables, using the following rules:
- header names are prefixed with "HTTP_"
- the header name is made uppercase
- all hyphens ("-") in the name are replaced by underscores ("_")
- the header value is left unchanged

So for a definition of HTTP_HOST you have to look at the spec for the
Host: header of the http protocol:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.23
And yes, Richard is correct: the port number is obligatory in the host
header if different from "80". I had a look at the thttpd source and indeed
it drops the port from the Host: header (in order to use the rest as
virtual hosting path) -- look at the libthttpd.c file.

> There are also SERVER_NAME and SERVER_PORT. Thttpd does supply 
> those, and they are named explicitly in every CGI document a 
> quick search turned up just now. Perhaps the host name should be 
> assembled from those two, omitting the port if it is 80 of course.

This won't work: SERVER_NAME is not necessarily the same as the host name
of the request. The cgi spec leaves room for this to be the system name,
the IP number (as text) or a domain name, which could be one of several in
the case of virtual domains.

However it is easy to patch thttpd to use the SERVER_PORT data to fix up
the HTTP_HOST information (same libthttpd.c file):
     if ( hc->hdrhost[0] != '\0' )
-      envp[envn++] = build_env( "HTTP_HOST=%s", hc->hdrhost );
+      envp[envn++] = build_env( "HTTP_HOST=%s:%d", hc->hdrhost, (int)
hc->hs->port );

This will append :80 for port 80, so you may want to special case that.

Paul




_______________________________________________
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users

Reply via email to