X-Git-Url: http://git.dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fsendfile.c;fp=src%2Fsendfile.c;h=f12e33e6ada9e9d5aecfeff376bf4e144fa97e8e;hb=b4164ce630753af81884d347b930625fb020b018;hp=76c0ad4576224def27512c6e6b16e21f67b38a3b;hpb=01b2ebcef044b1aaea39a3ec3b5d3ccf0f08e444;p=ashd.git diff --git a/src/sendfile.c b/src/sendfile.c index 76c0ad4..f12e33e 100644 --- a/src/sendfile.c +++ b/src/sendfile.c @@ -24,6 +24,7 @@ #include #include #include +#include #ifdef HAVE_CONFIG_H #include @@ -71,9 +72,28 @@ static char *getmimetype(char *file, struct stat *sb) return("application/xhtml+xml"); if(!strrcmp(file, ".txt")) return("text/plain"); + if(!strrcmp(file, ".py")) + return("text/plain"); + if(!strrcmp(file, ".c")) + return("text/plain"); return("application/octet-stream"); } +static void checkcache(char *file, struct stat *sb) +{ + char *hdr; + + if((hdr = getenv("REQ_IF_MODIFIED_SINCE")) != NULL) { + if(parsehttpdate(hdr) < sb->st_mtime) + return; + printf("HTTP/1.1 304 Not Modified\r\n"); + printf("Date: %s\r\n", fmthttpdate(time(NULL))); + printf("Content-Length: 0\r\n"); + printf("\r\n"); + exit(0); + } +} + int main(int argc, char **argv) { char *file; @@ -98,9 +118,13 @@ int main(int argc, char **argv) exit(1); } + checkcache(file, &sb); + printf("HTTP/1.1 200 OK\r\n"); printf("Content-Type: %s\r\n", getmimetype(file, &sb)); printf("Content-Length: %ji\r\n", (intmax_t)sb.st_size); + printf("Last-Modified: %s\r\n", fmthttpdate(sb.st_mtime)); + printf("Date: %s\r\n", fmthttpdate(time(NULL))); printf("\r\n"); fflush(stdout); if(strcasecmp(argv[1], "head"))