Skip to content

Instantly share code, notes, and snippets.

@marijnh
Created November 4, 2012 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marijnh/4013062 to your computer and use it in GitHub Desktop.
Save marijnh/4013062 to your computer and use it in GitHub Desktop.
Nginx patch to make WebDAV module respect if-unmodified-since
Index: src/http/modules/ngx_http_dav_module.c
===================================================================
--- src/http/modules/ngx_http_dav_module.c (revision 4898)
+++ src/http/modules/ngx_http_dav_module.c (working copy)
@@ -55,6 +55,9 @@
static ngx_int_t ngx_http_dav_copy_tree_file(ngx_tree_ctx_t *ctx,
ngx_str_t *path);
+static ngx_int_t ngx_http_dav_check_unmodified(ngx_http_request_t *r,
+ ngx_file_info_t *fi);
+
static ngx_int_t ngx_http_dav_depth(ngx_http_request_t *r, ngx_int_t dflt);
static ngx_int_t ngx_http_dav_error(ngx_log_t *log, ngx_err_t err,
ngx_int_t not_found, char *failed, u_char *path);
@@ -237,6 +240,7 @@
ngx_http_finalize_request(r, NGX_HTTP_CONFLICT);
return;
}
+ if (ngx_http_dav_check_unmodified(r, &fi)) return;
}
dlcf = ngx_http_get_module_loc_conf(r, ngx_http_dav_module);
@@ -353,6 +357,8 @@
} else {
+ if (ngx_http_dav_check_unmodified(r, &fi)) return NGX_DONE;
+
/*
* we do not need to test (r->uri.data[r->uri.len - 1] == '/')
* because ngx_link_info("/file/") returned NGX_ENOTDIR above
@@ -707,6 +713,8 @@
/* destination exists */
+ if (ngx_http_dav_check_unmodified(r, &fi)) return NGX_DONE;
+
if (ngx_is_dir(&fi) && !slash) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"\"%V\" could not be %Ved to collection \"%V\"",
@@ -967,6 +975,22 @@
return NGX_OK;
}
+static ngx_int_t
+ngx_http_dav_check_unmodified(ngx_http_request_t *r, ngx_file_info_t *fi)
+{
+ time_t date;
+ if (r->headers_in.if_unmodified_since) {
+ date =
+ ngx_http_parse_time(r->headers_in.if_unmodified_since->value.data,
+ r->headers_in.if_unmodified_since->value.len);
+ if (date < ngx_file_mtime(fi)) {
+ ngx_http_filter_finalize_request(r, NULL,
+ NGX_HTTP_PRECONDITION_FAILED);
+ return 1;
+ }
+ }
+ return 0;
+}
static ngx_int_t
ngx_http_dav_depth(ngx_http_request_t *r, ngx_int_t dflt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment