Permalink
Browse files

Support empty PUTs

  • Loading branch information...
1 parent be5a11e commit c6051556460561bac4b0931fd9436e37b84925a3 @schmichael committed Dec 29, 2010
Showing with 20 additions and 11 deletions.
  1. +20 −3 src/http/modules/ngx_http_dav_module.c
  2. +0 −8 src/http/ngx_http_request.c
@@ -202,6 +202,7 @@ ngx_http_dav_put_handler(ngx_http_request_t *r)
{
size_t root;
time_t date;
+ ngx_fd_t nfd;
ngx_str_t *temp, path;
ngx_uint_t status;
ngx_file_info_t fi;
@@ -257,9 +258,25 @@ ngx_http_dav_put_handler(ngx_http_request_t *r)
}
}
- if (ngx_ext_rename_file(temp, &path, &ext) != NGX_OK) {
- ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
+ if (&r->request_body->temp_file->file) {
+ if (ngx_ext_rename_file(temp, &path, &ext) != NGX_OK) {
+ ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
+ return;
+ }
+
+ } else {
+ nfd = ngx_open_file(path.data, NGX_FILE_WRONLY, NGX_FILE_TRUNCATE,
+ ext.access);
+
+ if (nfd == NGX_INVALID_FILE) {
+ (void) ngx_http_dav_error(r->connection->log, ngx_errno, 0,
+ "error trunctating file: %s", path.data);
+ ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
+ return;
+
+ }
+
+ ngx_close_file(nfd);
}
if (status == NGX_HTTP_CREATED) {
@@ -1527,14 +1527,6 @@ ngx_http_process_request_header(ngx_http_request_t *r)
}
}
- if (r->method & NGX_HTTP_PUT && r->headers_in.content_length_n == -1) {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent %V method without \"Content-Length\" header",
- &r->method_name);
- ngx_http_finalize_request(r, NGX_HTTP_LENGTH_REQUIRED);
- return NGX_ERROR;
- }
-
if (r->method & NGX_HTTP_TRACE) {
ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
"client sent TRACE method");

0 comments on commit c605155

Please sign in to comment.