On Sun, May 03, 2015 at 11:14:48AM -0500, Kyle Thompson wrote:
> On Sun, May 03, 2015 at 03:00:40PM +0000, Florian Obser wrote:
> > On Sat, Apr 18, 2015 at 12:19:46PM -0500, jmp wrote:
> > RFC 7232
> >
> > A recipient MUST ignore the If-Modified-Since header field if the
> > received field-value is not a valid HTTP-date, or if the request
> > method is neither GET nor HEAD.
> > ^^^^^^^^^^^^^^^^^^^^
>
> Does httpd allow any other types of requests through server_file.c? All
> other types of requests should only get sent through the CGI scripts. It
> doesn't make since to allow POST, PUT, etc.. through to the file
> handler.
yes, the check for that is later. This is better:
diff --git server_file.c server_file.c
index 3580bbb..42e2965 100644
--- server_file.c
+++ server_file.c
@@ -42,6 +42,7 @@ int server_file_request(struct httpd *, struct client *,
char *,
struct stat *);
int server_file_index(struct httpd *, struct client *, struct stat *);
int server_file_method(struct client *);
+int server_file_modified_since(struct http_descriptor *, struct stat *);
int
server_file_access(struct httpd *env, struct client *clt,
@@ -209,6 +210,9 @@ server_file_request(struct httpd *env, struct client *clt,
char *path,
goto abort;
}
+ if ((ret = server_file_modified_since(clt->clt_descreq, st)) != -1)
+ return ret;
+
/* Now open the file, should be readable or we have another problem */
if ((fd = open(path, O_RDONLY)) == -1)
goto abort;
@@ -469,3 +473,23 @@ server_file_error(struct bufferevent *bev, short error,
void *arg)
server_close(clt, "unknown event error");
return;
}
+
+int
+server_file_modified_since(struct http_descriptor * desc, struct stat * st)
+{
+ struct kv key, *since;
+ struct tm tm;
+
+ memset(&tm, 0, sizeof(struct 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) {
+ return (304);
+ }
+ }
+
+ return (-1);
+}
--
I'm not entirely sure you are real.