Fossil User Forum

/ext is missing SERVER_NAME when run locally?
Login

/ext is missing SERVER_NAME when run locally?

/ext is missing SERVER_NAME when run locally?

(1) By Stephan Beal (stephan) on 2020-12-12 04:49:00 [link] [source]

i'm experimenting with /ext as an alternative host for a CGI which i'd normally run via Apache and discovered that it's missing SERVER_NAME. Looking at the code, that var is certainly in the whitelist, and i'm wondering if someone else can confirm that they see this, too:

fossil ui --extroot /path/to/ext

In the extroot, place the file env.cgi with this content:

#!/bin/bash
echo -en "Status: 200 OK\r\n"
echo -en "Content-type: text/plain\r\n"
echo -en "\r\n"
env

Then visit it using http://localhost:8080/ext/env.cgi:

HTTP_ACCEPT_ENCODING=
SCRIPT_NAME=/ext/env.cgi
GATEWAY_INTERFACE=CGI/1.0
FOSSIL_NONCE=a577d31310669e59e3a7f0d89eac269459b8e962ee5a2b14
PATH_INFO=
DOCUMENT_ROOT=/home/pi/www/dv/fossil-ext
PWD=/home/pi/www/dv
REQUEST_URI=/ext/env.cgi
QUERY_STRING=
FOSSIL_URI=
HTTP_HOST=localhost:8080
HTTP_USER_AGENT=Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0
SHLVL=1
FOSSIL_CAPABILITIES=bcdefghijklmnopqrstwz234567AD
SCRIPT_FILENAME=/home/pi/www/dv/fossil-ext/env.cgi
SCRIPT_DIRECTORY=/home/pi/www/dv/fossil-ext
FOSSIL_REPOSITORY=/home/pi/fossil/darkventure.fossil
REMOTE_ADDR=127.0.0.1
FOSSIL_USER=stephan
REMOTE_USER=stephan
REQUEST_METHOD=GET
_=/usr/bin/env

It's not a big deal that SERVER_NAME is missing - it just stuck out at me because it caused a derived property (which is currently unused and will likely remain so) to be malformed.

:-?

(2) By Richard Hipp (drh) on 2020-12-12 13:55:59 in reply to 1 [source]

I'm attempting to add SERVER_NAME support to althttpd and Fossil, and I have a question:

Is SERVER_NAME exactly the same as HTTP_HOST? Or in the case of a TCP port specification in the URL (example: http://somedomain:8080/) does the ":8080" get appended to the SERVER_NAME as it does to HTTP_HOST or is the TCP port number stripped off?

So if you have Apache running on port 8080, and you use it to invoke a CGI, what does it show for the HTTP_HOST and SERVER_NAME environment variables?

The current behavior in althttpd.c seems to be that SERVER_NAME and HTTP_HOST are identical - they both include the TCP port number. I'm wondering if that is a bug that needs to be fixed.

(3) By Stephan Beal (stephan) on 2020-12-12 14:14:24 in reply to 2 [link] [source]

Is SERVER_NAME exactly the same as HTTP_HOST?

Good question. The same env script, from 8080, as above says:

SERVER_NAME=wh.local
...
HTTP_HOST=wh.local:8080
...
SERVER_SIGNATURE=<address>Apache/2.4.38 (Raspbian) Server at wh.local Port 8080</address>

(4) By Richard Hipp (drh) on 2020-12-12 15:12:59 in reply to 2 [link] [source]

I was misreading the althttpd.c source code. Turns out it does the same as Apache and strips the TCP port number off the end before setting the SERVER_NAME environment variable, but leaves the TCP port number intact for the HTTP_HOST environment variable.

(5) By Stephan Beal (stephan) on 2020-12-12 16:22:43 in reply to 4 [link] [source]

Reminder, in case this slipped by in/after f101e94da1f80571:

SERVER_NAME still includes the port number:

This is fossil version 2.14 [1cff8d3182] 2020-12-12 15:25:17 UTC
SERVER_NAME=wh.local:8080
...
HTTP_HOST=wh.local:8080

That's hosted via fossil server from /ext, not from Apache.