diff -rNC3 publicfile-0.52.orig/CHANGES publicfile-0.52/CHANGES *** publicfile-0.52.orig/CHANGES Tue Nov 9 08:23:46 1999 --- publicfile-0.52/CHANGES Fri Jan 10 10:09:18 2003 *************** *** 1,3 **** --- 1,14 ---- + 20030108 + improvement by Robert Thille : + stat .gz before file_open to avoid file not found error + 20011029 + feature (httpd): when a client requests / supplying a + header "Accept-Encoding" that contains the string "gzip" somewhere, + and if / would have been delivered and if /.gz + could have been delivered, too, and if /.gz is not older + than /, then /.gz is delivered with the + same Content-type as / and an additional header line + "Content-Encoding: gzip" - Peter Conrad 19991105 version: publicfile 0.50, alpha. 19991108 diff -rNC3 publicfile-0.52.orig/httpd.c publicfile-0.52/httpd.c *** publicfile-0.52.orig/httpd.c Tue Nov 9 08:23:46 1999 --- publicfile-0.52/httpd.c Fri Jan 10 10:08:38 2003 *************** *** 1,3 **** --- 1,4 ---- + #include #include "pathdecode.h" #include "file.h" #include "filetype.h" *************** *** 52,63 **** --- 53,66 ---- stralloc path = {0}; stralloc ims = {0}; int flagbody = 1; + int flaggzip = 0; char filebuf[1024]; struct tai now; stralloc nowstr = {0}; struct tai mtime; + struct tai mtimegz; struct tai mtimeage; stralloc mtimestr = {0}; *************** *** 101,105 **** --- 104,109 ---- } stralloc fn = {0}; + stralloc fngz = {0}; stralloc contenttype = {0}; *************** *** 106,111 **** --- 110,118 ---- void get(void) { unsigned long length; + unsigned long lengthgz; int fd; + int fdgz = -1; int r; + struct stat st; *************** *** 123,129 **** if (!stralloc_cats(&fn,"/")) _exit(21); if (!stralloc_cat(&fn,&path)) _exit(21); pathdecode(&fn); - if (!stralloc_0(&fn)) _exit(21); fd = file_open(fn.s,&mtime,&length,1); if (fd == -1) --- 131,148 ---- if (!stralloc_cats(&fn,"/")) _exit(21); if (!stralloc_cat(&fn,&path)) _exit(21); pathdecode(&fn); + if (flaggzip) { + if (!stralloc_copy(&fngz,&fn)) _exit(21); + if (!stralloc_cats(&fngz,".gz")) _exit(21); + if (!stralloc_0(&fngz)) _exit(21); + /* Only call file_open if we can stat the .gz file */ + if (!stat(fngz.s,&st)) + fdgz = file_open(fngz.s,&mtimegz,&lengthgz,1); + if (fdgz < 0) + flaggzip = 0; + } + + if (!stralloc_0(&fn)) _exit(21); fd = file_open(fn.s,&mtime,&length,1); if (fd == -1) *************** *** 131,134 **** if (protocolnum > 0) { tai_now(&now); if (!httpdate(&mtimestr,&mtime)) _exit(21); --- 150,164 ---- + if (flaggzip) { + if (tai_less(&mtimegz,&mtime)) { + flaggzip = 0; + close(fdgz); + } else { + close(fd); + fd = fdgz; + length = lengthgz; + } + } + if (protocolnum > 0) { tai_now(&now); if (!httpdate(&mtimestr,&mtime)) _exit(21); *************** *** 148,153 **** --- 178,185 ---- } filetype(fn.s,&contenttype); out_put(contenttype.s,contenttype.len); + if (flaggzip) + out_puts("Content-Encoding: gzip\r\n"); if (protocolnum >= 2) out_puts("Transfer-Encoding: chunked\r\n"); else { *************** *** 277,282 **** --- 309,315 ---- if (!path.len || (path.s[path.len - 1] == '/')) if (!stralloc_cats(&path,"index.html")) _exit(21); + flaggzip = 0; if (protocolnum > 0) { if (!stralloc_copys(&field,"")) _exit(21); for (;;) { *************** *** 302,307 **** --- 335,344 ---- if (!stralloc_append(&host,&field.s[i])) _exit(21); if (case_startb(field.s,field.len,"if-modified-since:")) if (!stralloc_copyb(&ims,field.s + 18,field.len - 18)) _exit(21); + if (case_startb(field.s,field.len,"accept-encoding:")) + for (i = 16; i < field.len-3; i++) + if (case_startb(field.s+i,field.len-i,"gzip")) + flaggzip = 1; field.len = 0; } if (!line.len) break; diff -rNC3 publicfile-0.52.orig/rts.tests publicfile-0.52/rts.tests *** publicfile-0.52.orig/rts.tests Tue Nov 9 08:23:46 1999 --- publicfile-0.52/rts.tests Fri Jan 10 10:08:38 2003 *************** *** 198,203 **** --- 198,209 ---- ' | ( ./httpd 2>&1; echo $? ) | sed 's/^Date: .*/Date: .../' + echo "--- httpd handles Accept-Encoding" + gzip -9 <0/foo >0/foo.gz + echo 'GET foo HTTP/1.0 + Accept-Encoding: gzip + + ' | ( ./httpd 2>&1; echo $? ) | sed 's/^Date: .*/Date: .../' echo '--- ftpd rejects unrecognized requests'