Merge branch 'master' of git.dolda2000.com:/srv/git/r/ashd
authorFredrik Tolf <fredrik@dolda2000.com>
Sun, 26 Jun 2011 05:17:47 +0000 (07:17 +0200)
committerFredrik Tolf <fredrik@dolda2000.com>
Sun, 26 Jun 2011 05:17:47 +0000 (07:17 +0200)
doc/dirplex.doc
lib/req.c
lib/req.h
python/doc/ashd-wsgi.doc
src/htparser.c

index 362a5d7..e4c3b3e 100644 (file)
@@ -49,16 +49,20 @@ Mapping URLs into physical files is an iterative procedure, each step
 looking in one single physical directory, starting with 'DIR'. For
 each step, a path element is stripped off the beginning of the rest
 string and examined, the path element being either the leading part of
-the rest string up until the first slash, or the entire rest string if
-it contains no slashes. If the rest string is empty, the directory
-being examined is considered the result of the mapping. Otherwise, any
-escape sequences in the path element under consideration are unescaped
-before examining it.
+the rest string up until (but not including) the first slash, or the
+entire rest string if it contains no slashes. If the rest string is
+empty, the directory being examined is considered the result of the
+mapping. Otherwise, any escape sequences in the path element under
+consideration are unescaped before examining it.
 
 If the path element names a directory in the current directory, the
-procedure continues in that directory. If it names a file, that file
-is considered the result of the mapping (even if the rest string has
-not been exhausted yet).
+procedure continues in that directory, unless there is nothing left of
+the rest string, in which case *dirplex* responds with a HTTP 301
+redirect to the same URL, but ending with a slash. Otherwise, the
+remaining rest string begins with a slash, which is stripped off
+before continuing. If the path element names a file, that file is
+considered the result of the mapping (even if the rest string has not
+been exhausted yet).
 
 If the path element does not name anything in the directory under
 consideration, but contains no dots, then the directory is searched
index da8e3f0..662df0f 100644 (file)
--- a/lib/req.c
+++ b/lib/req.c
@@ -164,6 +164,72 @@ fail:
     return(-1);
 }
 
+struct hthead *parseresponse(FILE *in)
+{
+    struct hthead *req;
+    int code;
+    struct charbuf ver, msg;
+    int c;
+    
+    req = NULL;
+    bufinit(ver);
+    bufinit(msg);
+    code = 0;
+    while(1) {
+       c = getc(in);
+       if(c == ' ') {
+           break;
+       } else if((c == EOF) || (c < 32) || (c >= 128)) {
+           goto fail;
+       } else {
+           bufadd(ver, c);
+           if(ver.d >= 128)
+               goto fail;
+       }
+    }
+    while(1) {
+       c = getc(in);
+       if(c == ' ') {
+           break;
+       } else if((c == EOF) || (c < '0') || (c > '9')) {
+           goto fail;
+       } else {
+           code = (code * 10) + (c - '0');
+           if(code >= 10000)
+               goto fail;
+       }
+    }
+    while(1) {
+       c = getc(in);
+       if(c == 10) {
+           break;
+       } else if(c == 13) {
+       } else if((c == EOF) || (c < 32)) {
+           goto fail;
+       } else {
+           bufadd(msg, c);
+           if(msg.d >= 512)
+               goto fail;
+       }
+    }
+    bufadd(msg, 0);
+    bufadd(ver, 0);
+    req = mkresp(code, msg.b, ver.b);
+    if(parseheaders(req, in))
+       goto fail;
+    goto out;
+    
+fail:
+    if(req != NULL) {
+       freehthead(req);
+       req = NULL;
+    }
+out:
+    buffree(msg);
+    buffree(ver);
+    return(req);
+}
+
 void replrest(struct hthead *head, char *rest)
 {
     char *tmp;
index 752ff77..71a7a06 100644 (file)
--- a/lib/req.h
+++ b/lib/req.h
@@ -22,6 +22,7 @@ int sendreq(int sock, struct hthead *req, int fd);
 int recvreq(int sock, struct hthead **reqp);
 void replrest(struct hthead *head, char *rest);
 int parseheaders(struct hthead *head, FILE *in);
+struct hthead *parseresponse(FILE *in);
 int writeresp(FILE *out, struct hthead *resp);
 char *unquoteurl(char *in);
 
index b73f90d..9b950b8 100644 (file)
@@ -59,7 +59,7 @@ OPTIONS
        Allow at most 'LIMIT' requests to run concurrently. If a new
        request is made when 'LIMIT' requests are executing, the new
        request will wait up to ten seconds for one of them to
-       complete; if none does, the *ashd-wsgi* will assume that the
+       complete; if none does, *ashd-wsgi* will assume that the
        process is foobar and *abort*(3).
 
 PROTOCOL
index bc8f7fd..a195fab 100644 (file)
@@ -127,72 +127,6 @@ out:
     return(req);
 }
 
-static struct hthead *parseresp(FILE *in)
-{
-    struct hthead *req;
-    int code;
-    struct charbuf ver, msg;
-    int c;
-    
-    req = NULL;
-    bufinit(ver);
-    bufinit(msg);
-    code = 0;
-    while(1) {
-       c = getc(in);
-       if(c == ' ') {
-           break;
-       } else if((c == EOF) || (c < 32) || (c >= 128)) {
-           goto fail;
-       } else {
-           bufadd(ver, c);
-           if(ver.d >= 128)
-               goto fail;
-       }
-    }
-    while(1) {
-       c = getc(in);
-       if(c == ' ') {
-           break;
-       } else if((c == EOF) || (c < '0') || (c > '9')) {
-           goto fail;
-       } else {
-           code = (code * 10) + (c - '0');
-           if(code >= 10000)
-               goto fail;
-       }
-    }
-    while(1) {
-       c = getc(in);
-       if(c == 10) {
-           break;
-       } else if(c == 13) {
-       } else if((c == EOF) || (c < 32)) {
-           goto fail;
-       } else {
-           bufadd(msg, c);
-           if(msg.d >= 512)
-               goto fail;
-       }
-    }
-    bufadd(msg, 0);
-    bufadd(ver, 0);
-    req = mkresp(code, msg.b, ver.b);
-    if(parseheaders(req, in))
-       goto fail;
-    goto out;
-    
-fail:
-    if(req != NULL) {
-       freehthead(req);
-       req = NULL;
-    }
-out:
-    buffree(msg);
-    buffree(ver);
-    return(req);
-}
-
 static off_t passdata(FILE *in, FILE *out, off_t max)
 {
     size_t read;
@@ -318,7 +252,7 @@ void serve(FILE *in, struct conn *conn)
        /* Make sure to send EOF */
        shutdown(pfds[1], SHUT_WR);
        
-       if((resp = parseresp(out)) == NULL)
+       if((resp = parseresponse(out)) == NULL)
            break;
        replstr(&resp->ver, req->ver);