comparison src/http/modules/ngx_http_dav_module.c @ 1815:1e2fb527f9c0

log DELETE errors
author Igor Sysoev <igor@sysoev.ru>
date Sun, 30 Dec 2007 10:24:43 +0000
parents d466c739b54b
children 20a2512aacc4
comparison
equal deleted inserted replaced
1814:d466c739b54b 1815:1e2fb527f9c0
343 343
344 static ngx_int_t 344 static ngx_int_t
345 ngx_http_dav_delete_handler(ngx_http_request_t *r) 345 ngx_http_dav_delete_handler(ngx_http_request_t *r)
346 { 346 {
347 size_t root; 347 size_t root;
348 ngx_err_t err;
348 ngx_int_t rc, depth; 349 ngx_int_t rc, depth;
349 ngx_uint_t dir; 350 ngx_uint_t dir;
350 ngx_str_t path; 351 ngx_str_t path;
351 ngx_file_info_t fi; 352 ngx_file_info_t fi;
352 353
353 if (r->headers_in.content_length_n > 0) { 354 if (r->headers_in.content_length_n > 0) {
355 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
356 "DELETE with body is unsupported");
354 return NGX_HTTP_UNSUPPORTED_MEDIA_TYPE; 357 return NGX_HTTP_UNSUPPORTED_MEDIA_TYPE;
355 } 358 }
356 359
357 ngx_http_map_uri_to_path(r, &path, &root, 0); 360 ngx_http_map_uri_to_path(r, &path, &root, 0);
358 361
359 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 362 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
360 "http delete filename: \"%s\"", path.data); 363 "http delete filename: \"%s\"", path.data);
361 364
362 if (ngx_file_info(path.data, &fi) == -1) { 365 if (ngx_file_info(path.data, &fi) == -1) {
363 return ngx_http_dav_error(r->connection->log, ngx_errno, 366 err = ngx_errno;
364 NGX_HTTP_NOT_FOUND, ngx_file_info_n, 367
365 path.data); 368 rc = (err == NGX_ENOTDIR) ? NGX_HTTP_CONFLICT : NGX_HTTP_NOT_FOUND;
369
370 return ngx_http_dav_error(r->connection->log, err,
371 rc, ngx_file_info_n, path.data);
366 } 372 }
367 373
368 if (ngx_is_dir(&fi)) { 374 if (ngx_is_dir(&fi)) {
369 375
370 if (r->uri.data[r->uri.len - 1] != '/') { 376 if (r->uri.data[r->uri.len - 1] != '/') {
371 /* TODO: 301 */ 377 ngx_log_error(NGX_LOG_ERR, r->connection->log, NGX_EISDIR,
378 "DELETE \"%s\" failed", path.data);
379 return NGX_HTTP_CONFLICT;
380 }
381
382 depth = ngx_http_dav_depth(r, NGX_HTTP_DAV_INFINITY_DEPTH);
383
384 if (depth != NGX_HTTP_DAV_INFINITY_DEPTH) {
385 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
386 "\"Depth\" header must be infinity");
372 return NGX_HTTP_BAD_REQUEST; 387 return NGX_HTTP_BAD_REQUEST;
373 } 388 }
374 389
375 depth = ngx_http_dav_depth(r, NGX_HTTP_DAV_INFINITY_DEPTH);
376
377 if (depth != NGX_HTTP_DAV_INFINITY_DEPTH) {
378 return NGX_HTTP_BAD_REQUEST;
379 }
380
381 path.len -= 2; /* omit "/\0" */ 390 path.len -= 2; /* omit "/\0" */
382 391
383 dir = 1; 392 dir = 1;
384 393
385 } else { 394 } else {
386 395
387 depth = ngx_http_dav_depth(r, 0); 396 depth = ngx_http_dav_depth(r, 0);
388 397
389 if (depth != 0 && depth != NGX_HTTP_DAV_INFINITY_DEPTH) { 398 if (depth != 0 && depth != NGX_HTTP_DAV_INFINITY_DEPTH) {
399 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
400 "\"Depth\" header must be 0 or infinity");
390 return NGX_HTTP_BAD_REQUEST; 401 return NGX_HTTP_BAD_REQUEST;
391 } 402 }
392 403
393 dir = 0; 404 dir = 0;
394 } 405 }