diff options
author | kraxel <kraxel> | 2004-06-10 09:45:50 +0000 |
---|---|---|
committer | kraxel <kraxel> | 2004-06-10 09:45:50 +0000 |
commit | 7a9d340846d49f5816c0b2c869ad91b144f7c5c3 (patch) | |
tree | ba90d0d7d289336b8f45976bef033cce06734963 /request.c | |
parent | c73269a22b7fdbff11064ef0ab182a4705bf8024 (diff) | |
download | webfs-7a9d340846d49f5816c0b2c869ad91b144f7c5c3.tar.gz |
- rewrite timestamp handling: strcmp rfc1123 dates instead of attempt
to parse the date strings.
Diffstat (limited to 'request.c')
-rw-r--r-- | request.c | 59 |
1 files changed, 28 insertions, 31 deletions
@@ -87,6 +87,7 @@ read_request(struct REQUEST *req, int pipelined) /* ---------------------------------------------------------------------- */ +#if 0 static time_t parse_date(char *line) { @@ -125,6 +126,7 @@ parse_date(char *line) return mktime(&tm); } +#endif static off_t parse_off_t(char *str, int *pos) @@ -145,9 +147,6 @@ parse_ranges(struct REQUEST *req) char *h,*line = req->range_hdr; int i,off; - if (req->if_range > 0 && req->if_range != req->bst.st_mtime) - return 0; - for (h = line, req->ranges=1; *h != '\n' && *h != '\0'; h++) if (*h == ',') req->ranges++; @@ -353,7 +352,6 @@ parse_request(struct REQUEST *req) { char filename[MAX_PATH+1], proto[MAX_MISC+1], *h; int port, rc, len; - time_t t; struct passwd *pw=NULL; if (debug > 2) @@ -429,27 +427,13 @@ parse_request(struct REQUEST *req) req->hostname); } else if (0 == strncasecmp(h,"If-Modified-Since: ",19)) { - if (-1 != (t = parse_date(h+19))) { - req->if_modified = t; - if (debug) - fprintf(stderr,"%03d: if-modified-since: %s", - req->fd,ctime(&t)); - } + req->if_modified = h+19; } else if (0 == strncasecmp(h,"If-Unmodified-Since: ",21)) { - if (-1 != (t = parse_date(h+21))) { - req->if_unmodified = t; - if (debug) - fprintf(stderr,"%03d: if-unmodified-since: %s", - req->fd,ctime(&t)); - } + req->if_unmodified = h+21; } else if (0 == strncasecmp(h,"If-Range: ",10)) { - if (-1 != (t = parse_date(h+10))) { - req->if_range = t; - if (debug) - fprintf(stderr,"%03d: if-range: %s\n",req->fd,ctime(&t)); - } + req->if_range = h+10; } else if (0 == strncasecmp(h,"Authorization: Basic ",21)) { decode_base64(req->auth,h+21,sizeof(req->auth)-1); @@ -462,6 +446,17 @@ parse_request(struct REQUEST *req) req->range_hdr = h+13; } } + if (debug) { + if (req->if_modified) + fprintf(stderr,"%03d: if-modified-since: \"%s\"\n", + req->fd, req->if_modified); + if (req->if_unmodified) + fprintf(stderr,"%03d: if-unmodified-since: \"%s\"\n", + req->fd, req->if_unmodified); + if (req->if_range) + fprintf(stderr,"%03d: if-range: \"%s\"\n", + req->fd, req->if_range); + } /* take care about the hostname */ if (virtualhosts) { @@ -556,21 +551,22 @@ parse_request(struct REQUEST *req) } return; } + strftime(req->mtime, sizeof(req->mtime), RFC1123, gmtime(&req->bst.st_mtime)); req->mime = "text/html"; req->dir = get_dir(req,filename); - t = req->dir->add; if (NULL == req->body) { /* We arrive here if opendir failed, probably due to -EPERM * It does exist (see the stat() call above) */ mkerror(req,403,1); return; - } else if (req->if_modified > 0 && req->if_modified == t) { + } else if (NULL != req->if_modified && + 0 == strcmp(req->if_modified, req->mtime)) { /* 304 not modified */ - mkheader(req,304,t); + mkheader(req,304); req->head_only = 1; } else { /* 200 OK */ - mkheader(req,200,t); + mkheader(req,200); } return; } @@ -610,22 +606,23 @@ parse_request(struct REQUEST *req) /* it is /really/ a regular file */ req->mime = get_mime(filename); - if (req->if_range > 0 && req->if_range != req->bst.st_mtime) + strftime(req->mtime, sizeof(req->mtime), RFC1123, gmtime(&req->bst.st_mtime)); + if (NULL != req->if_range && 0 != strcmp(req->if_range, req->mtime)) /* mtime mismatch -> no ranges */ req->ranges = 0; - if (req->if_unmodified > 0 && req->if_unmodified != req->bst.st_mtime) { + if (NULL != req->if_unmodified && 0 != strcmp(req->if_unmodified, req->mtime)) { /* 412 precondition failed */ mkerror(req,412,1); - } else if (req->if_modified > 0 && req->if_modified == req->bst.st_mtime) { + } else if (NULL != req->if_modified && 0 == strcmp(req->if_modified, req->mtime)) { /* 304 not modified */ - mkheader(req,304,req->bst.st_mtime); + mkheader(req,304); req->head_only = 1; } else if (req->ranges > 0) { /* send byte range(s) */ - mkheader(req,206,req->bst.st_mtime); + mkheader(req,206); } else { /* normal */ - mkheader(req,200,req->bst.st_mtime); + mkheader(req,200); } return; } |