Ticket #242: nginx_dav_if-unmodified-since.patch

File nginx_dav_if-unmodified-since.patch, 2.1 KB (added by Marijn Haverbeke, 14 years ago)

Path that solves the problem for me

  • src/http/modules/ngx_http_dav_module.c

     
    5555static ngx_int_t ngx_http_dav_copy_tree_file(ngx_tree_ctx_t *ctx,
    5656    ngx_str_t *path);
    5757
     58static ngx_int_t ngx_http_dav_check_unmodified(ngx_http_request_t *r,
     59                                               ngx_file_info_t *fi);
     60
    5861static ngx_int_t ngx_http_dav_depth(ngx_http_request_t *r, ngx_int_t dflt);
    5962static ngx_int_t ngx_http_dav_error(ngx_log_t *log, ngx_err_t err,
    6063    ngx_int_t not_found, char *failed, u_char *path);
     
    237240            ngx_http_finalize_request(r, NGX_HTTP_CONFLICT);
    238241            return;
    239242        }
     243        if (ngx_http_dav_check_unmodified(r, &fi)) return;
    240244    }
    241245
    242246    dlcf = ngx_http_get_module_loc_conf(r, ngx_http_dav_module);
     
    353357
    354358    } else {
    355359
     360        if (ngx_http_dav_check_unmodified(r, &fi)) return NGX_DONE;
     361
    356362        /*
    357363         * we do not need to test (r->uri.data[r->uri.len - 1] == '/')
    358364         * because ngx_link_info("/file/") returned NGX_ENOTDIR above
     
    707713
    708714        /* destination exists */
    709715
     716        if (ngx_http_dav_check_unmodified(r, &fi)) return NGX_DONE;
     717
    710718        if (ngx_is_dir(&fi) && !slash) {
    711719            ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
    712720                          "\"%V\" could not be %Ved to collection \"%V\"",
     
    967975    return NGX_OK;
    968976}
    969977
     978static ngx_int_t
     979ngx_http_dav_check_unmodified(ngx_http_request_t *r, ngx_file_info_t *fi)
     980{
     981    time_t date;
     982    if (r->headers_in.if_unmodified_since) {
     983        date =
     984            ngx_http_parse_time(r->headers_in.if_unmodified_since->value.data,
     985                                r->headers_in.if_unmodified_since->value.len);
     986        if (date < ngx_file_mtime(fi)) {
     987            ngx_http_filter_finalize_request(r, NULL,
     988                                             NGX_HTTP_PRECONDITION_FAILED);
     989            return 1;
     990        }
     991    }
     992    return 0;
     993}
    970994
    971995static ngx_int_t
    972996ngx_http_dav_depth(ngx_http_request_t *r, ngx_int_t dflt)