comparison src/http/modules/ngx_http_dav_module.c @ 7602:b399246ea45d

Saved some memory allocations. In configurations when "root" has variables, some modules unnecessarily allocated memory for the "Location" header value.
author Ruslan Ermilov <ru@nginx.com>
date Mon, 16 Dec 2019 15:19:01 +0300
parents c1a7d3672653
children f609c0ac2972
comparison
equal deleted inserted replaced
7601:c1a7d3672653 7602:b399246ea45d
54 ngx_str_t *path); 54 ngx_str_t *path);
55 55
56 static ngx_int_t ngx_http_dav_depth(ngx_http_request_t *r, ngx_int_t dflt); 56 static ngx_int_t ngx_http_dav_depth(ngx_http_request_t *r, ngx_int_t dflt);
57 static ngx_int_t ngx_http_dav_error(ngx_log_t *log, ngx_err_t err, 57 static ngx_int_t ngx_http_dav_error(ngx_log_t *log, ngx_err_t err,
58 ngx_int_t not_found, char *failed, u_char *path); 58 ngx_int_t not_found, char *failed, u_char *path);
59 static ngx_int_t ngx_http_dav_location(ngx_http_request_t *r, u_char *path); 59 static ngx_int_t ngx_http_dav_location(ngx_http_request_t *r);
60 static void *ngx_http_dav_create_loc_conf(ngx_conf_t *cf); 60 static void *ngx_http_dav_create_loc_conf(ngx_conf_t *cf);
61 static char *ngx_http_dav_merge_loc_conf(ngx_conf_t *cf, 61 static char *ngx_http_dav_merge_loc_conf(ngx_conf_t *cf,
62 void *parent, void *child); 62 void *parent, void *child);
63 static ngx_int_t ngx_http_dav_init(ngx_conf_t *cf); 63 static ngx_int_t ngx_http_dav_init(ngx_conf_t *cf);
64 64
283 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); 283 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
284 return; 284 return;
285 } 285 }
286 286
287 if (status == NGX_HTTP_CREATED) { 287 if (status == NGX_HTTP_CREATED) {
288 if (ngx_http_dav_location(r, path.data) != NGX_OK) { 288 if (ngx_http_dav_location(r) != NGX_OK) {
289 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); 289 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
290 return; 290 return;
291 } 291 }
292 292
293 r->headers_out.content_length_n = 0; 293 r->headers_out.content_length_n = 0;
518 "http mkcol path: \"%s\"", path.data); 518 "http mkcol path: \"%s\"", path.data);
519 519
520 if (ngx_create_dir(path.data, ngx_dir_access(dlcf->access)) 520 if (ngx_create_dir(path.data, ngx_dir_access(dlcf->access))
521 != NGX_FILE_ERROR) 521 != NGX_FILE_ERROR)
522 { 522 {
523 *(p - 1) = '/'; 523 if (ngx_http_dav_location(r) != NGX_OK) {
524
525 if (ngx_http_dav_location(r, path.data) != NGX_OK) {
526 return NGX_HTTP_INTERNAL_SERVER_ERROR; 524 return NGX_HTTP_INTERNAL_SERVER_ERROR;
527 } 525 }
528 526
529 return NGX_HTTP_CREATED; 527 return NGX_HTTP_CREATED;
530 } 528 }
1068 return rc; 1066 return rc;
1069 } 1067 }
1070 1068
1071 1069
1072 static ngx_int_t 1070 static ngx_int_t
1073 ngx_http_dav_location(ngx_http_request_t *r, u_char *path) 1071 ngx_http_dav_location(ngx_http_request_t *r)
1074 { 1072 {
1075 u_char *location;
1076 ngx_http_core_loc_conf_t *clcf;
1077
1078 r->headers_out.location = ngx_list_push(&r->headers_out.headers); 1073 r->headers_out.location = ngx_list_push(&r->headers_out.headers);
1079 if (r->headers_out.location == NULL) { 1074 if (r->headers_out.location == NULL) {
1080 return NGX_ERROR; 1075 return NGX_ERROR;
1081 } 1076 }
1082 1077
1083 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1084
1085 if (!clcf->alias && clcf->root_lengths == NULL) {
1086 location = path + clcf->root.len;
1087
1088 } else {
1089 location = ngx_pnalloc(r->pool, r->uri.len);
1090 if (location == NULL) {
1091 ngx_http_clear_location(r);
1092 return NGX_ERROR;
1093 }
1094
1095 ngx_memcpy(location, r->uri.data, r->uri.len);
1096 }
1097
1098 r->headers_out.location->hash = 1; 1078 r->headers_out.location->hash = 1;
1099 ngx_str_set(&r->headers_out.location->key, "Location"); 1079 ngx_str_set(&r->headers_out.location->key, "Location");
1100 r->headers_out.location->value.len = r->uri.len; 1080 r->headers_out.location->value = r->uri;
1101 r->headers_out.location->value.data = location;
1102 1081
1103 return NGX_OK; 1082 return NGX_OK;
1104 } 1083 }
1105 1084
1106 1085