Messages in this thread | | | Date | Sat, 12 Jun 1999 14:15:22 +0100 (GMT) | From | Riley Williams <> | Subject | Re: generalizing khttpd |
| |
Hi Ben.
>>> If the URL has ? in it, there CANNOT be a file corresponding >>> with it, so this one caught by kHTTPd right now, using the >>> rule "When not servable, do userspace".
>> Don't be too sure of that - try the following command:
>> Q> touch 'x?y' ; ls -l 'x?y'
>> I've just tried it, and it works fine here...
> It doesn't matter whether can create a file containing `?'. > `?' signifies the beginning of a URL query string. You'll find > that to access the file above through a web server you actually > need to specify x%3fy as the URL.
I know, and that's what I was pointing out to the person I was replying to - reread his comments and you'll see that the current design of khttpd (at least as he specified it) would happily have taken x?y as a filename if such a file happenned to have existed.
I therefore repeat the claim I made, which is that any web server seeing a URL with a ? in it MUST assume that the URL in question references a dynamic file.
However, you've brought up a point that I'd certainly overlooked, and I suspect Arjan had as well, which is the %xx notation for certain characters in filenames.
Arjan: Allowing for those sequences, the correct handling of URL's as far as khttpd is concerned would be similar to the enclosed shell script, at least as I understand it.
Best wishes from Riley.
+----------------------------------------------------------------------+ | There is something frustrating about the quality and speed of Linux | | development, ie., the quality is too high and the speed is too high, | | in other words, I can implement this XXXX feature, but I bet someone | | else has already done so and is just about to release their patch. | +----------------------------------------------------------------------+ * ftp://ftp.MemAlpha.cx/pub/rhw/Linux * http://www.MemAlpha.cx/kernel.versions.html
#!/bin/bash if [ $# -eq 0 ]; then echo "Usage: `basename $0` url..." >&2 exit 127 fi
# State the directory entries to be regarded as indicating dynamic # URL's.
DYNAMIC_DIRS='cgi-bin'
# Function to convert any %XX sequences in its parameter to the # equivalent character, as per standard WWW URL practice.
function convert() { declare -i N=0 L=`echo -n "$1" | wc -c` local CH R=''
while [ $N -lt $L ]; do N=$N+1 CH=`echo "$URL" | cut -b $N` if [ "$CH" = "%" -a $N -lt $[$L-1] ]; then N=$N+2 CH=`echo "$URL" | cut -b $[$N-1]-$N` CH=`printf "\x$CH"` fi R="${R}${CH}" done echo "$R" }
# Scan through the URL's passed as command-line parameters.
for URL do ORIG="$URL"
# Default result is STATIC.
RESULT=STATIC
# If there's a ? in it, then it's always DYNAMIC.
if echo "$URL" | fgrep '?' > /dev/null ; then RESULT=DYNAMIC fi
# If there's a trailing / then treat it as DYNAMIC.
if [ "`echo \"$URL\" | rev | cut -b 1`" = "/" ]; then RESULT=DYNAMIC fi
# If there are any %XX sequences in the string, convert them.
if echo "$URL" | fgrep '%' > /dev/null ; then URL=`convert "$URL"` fi
# If it either doesn't exist or isn't a regular file, treat it # as dynamic.
if [ ! -f "$URL" ]; then RESULT=DYNAMIC fi
# If it's not now listed as STATIC then no further tests are needed.
if [ $RESULT = STATIC ]; then
# If it's an eexcutable file, treat it as dynamic.
if [ -x "$URL" ]; then RESULT=DYNAMIC else
# Check whether any of the directories in the path specify # that it's dynamic.
for DIR in $DYNAMIC_DIRS ; do if echo "$URL" | fgrep "${DIR}" > /dev/null ; then RESULT=DYNAMIC break fi done
fi fi
# Display the result.
printf '%-8s %s\n' "${RESULT}:" "$ORIG" done
| |