summaryrefslogtreecommitdiff
path: root/usr.sbin/httpd/server_file.c
diff options
context:
space:
mode:
authorReyk Floeter <reyk@cvs.openbsd.org>2015-07-17 21:53:58 +0000
committerReyk Floeter <reyk@cvs.openbsd.org>2015-07-17 21:53:58 +0000
commitf44d980c11043b1bd71bf4519fa27dcbcba96f11 (patch)
treedfae73862dea042690f6f090662ca26bdca94324 /usr.sbin/httpd/server_file.c
parent3d8fddd6fecdbd1fd4b0927af6b30beba05e092f (diff)
Adjust server_file_modified_since() to our style. Please keep httpd clean.
Diffstat (limited to 'usr.sbin/httpd/server_file.c')
-rw-r--r--usr.sbin/httpd/server_file.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/usr.sbin/httpd/server_file.c b/usr.sbin/httpd/server_file.c
index 16b47d06cba..87fe865b9af 100644
--- a/usr.sbin/httpd/server_file.c
+++ b/usr.sbin/httpd/server_file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server_file.c,v 1.55 2015/07/16 19:05:28 reyk Exp $ */
+/* $OpenBSD: server_file.c,v 1.56 2015/07/17 21:53:57 reyk Exp $ */
/*
* Copyright (c) 2006 - 2015 Reyk Floeter <reyk@openbsd.org>
@@ -232,7 +232,7 @@ server_file_request(struct httpd *env, struct client *clt, char *path,
}
if ((ret = server_file_modified_since(clt->clt_descreq, st)) != -1)
- return ret;
+ return (ret);
/* Now open the file, should be readable or we have another problem */
if ((fd = open(path, O_RDONLY)) == -1)
@@ -633,20 +633,24 @@ server_file_error(struct bufferevent *bev, short error, void *arg)
}
int
-server_file_modified_since(struct http_descriptor * desc, struct stat * st)
+server_file_modified_since(struct http_descriptor *desc, struct stat *st)
{
- struct kv key, *since;
- struct tm tm;
-
- memset(&tm, 0, sizeof(struct tm));
+ struct kv key, *since;
+ struct tm tm;
key.kv_key = "If-Modified-Since";
if ((since = kv_find(&desc->http_headers, &key)) != NULL &&
- since->kv_value != NULL) {
- if (strptime(since->kv_value, "%a, %d %h %Y %T %Z", &tm) !=
- NULL && timegm(&tm) >= st->st_mtim.tv_sec) {
+ since->kv_value == NULL) {
+ memset(&tm, 0, sizeof(struct tm));
+
+ /*
+ * Return "Not modified" if the file hasn't changed since
+ * the requested time.
+ */
+ if (strptime(since->kv_value,
+ "%a, %d %h %Y %T %Z", &tm) != NULL &&
+ timegm(&tm) >= st->st_mtim.tv_sec)
return (304);
- }
}
return (-1);