Refactor responsefile()
Add some comments and improve coding-style.
This commit is contained in:
parent
68535cc04f
commit
f915f82a40
1 changed files with 8 additions and 6 deletions
14
quark.c
14
quark.c
|
@ -189,9 +189,9 @@ responsefile(void) {
|
||||||
struct stat st;
|
struct stat st;
|
||||||
time_t t;
|
time_t t;
|
||||||
|
|
||||||
r = stat(reqbuf, &st);
|
if((r = stat(reqbuf, &st)) == -1 || (ffd = open(reqbuf, O_RDONLY)) == -1) {
|
||||||
if(r == -1 || (ffd = open(reqbuf, O_RDONLY)) == -1) {
|
/* file not found */
|
||||||
logerrmsg("%s requests unknown path %s\n", host, reqbuf);
|
logerrmsg("%s requests unknown file %s\n", host, reqbuf);
|
||||||
if(putresentry(HEADER, HttpNotFound, tstamp())
|
if(putresentry(HEADER, HttpNotFound, tstamp())
|
||||||
|| putresentry(CONTENTTYPE, texthtml))
|
|| putresentry(CONTENTTYPE, texthtml))
|
||||||
return;
|
return;
|
||||||
|
@ -199,13 +199,14 @@ responsefile(void) {
|
||||||
writetext("\r\n<html><body>404 Not Found</body></html>\r\n");
|
writetext("\r\n<html><body>404 Not Found</body></html>\r\n");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
/* check if modified */
|
||||||
t = st.st_mtim.tv_sec;
|
t = st.st_mtim.tv_sec;
|
||||||
memcpy(mod, asctime(gmtime(&t)), 24);
|
memcpy(mod, asctime(gmtime(&t)), 24);
|
||||||
mod[24] = 0;
|
mod[24] = 0;
|
||||||
if(!strcmp(reqmod, mod)) {
|
if(!strcmp(reqmod, mod) && !putresentry(HEADER, HttpNotModified, tstamp())) {
|
||||||
if(putresentry(HEADER, HttpNotModified, tstamp()))
|
/* not modified, we're done here*/
|
||||||
return;
|
|
||||||
} else {
|
} else {
|
||||||
|
/* determine mime-type */
|
||||||
if((p = strrchr(reqbuf, '.'))) {
|
if((p = strrchr(reqbuf, '.'))) {
|
||||||
p++;
|
p++;
|
||||||
for(i = 0; i < LENGTH(servermimes); i++)
|
for(i = 0; i < LENGTH(servermimes); i++)
|
||||||
|
@ -214,6 +215,7 @@ responsefile(void) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/* serve file */
|
||||||
if(putresentry(HEADER, HttpOk, tstamp())
|
if(putresentry(HEADER, HttpOk, tstamp())
|
||||||
|| putresentry(MODIFIED, mod)
|
|| putresentry(MODIFIED, mod)
|
||||||
|| putresentry(CONTENTLEN, st.st_size)
|
|| putresentry(CONTENTLEN, st.st_size)
|
||||||
|
|
Loading…
Reference in a new issue