diff options
Diffstat (limited to 'src/http/ngx_http_core_module.c')
-rw-r--r-- | src/http/ngx_http_core_module.c | 74 |
1 files changed, 50 insertions, 24 deletions
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c index 0643a87fd..4c6cfc073 100644 --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -911,6 +911,41 @@ ngx_http_set_content_type(ngx_http_request_t *r) ngx_int_t +ngx_http_set_exten(ngx_http_request_t *r) +{ + ngx_int_t i; + + r->exten.len = 0; + r->exten.data = NULL; + + for (i = r->uri.len - 1; i > 1; i--) { + if (r->uri.data[i] == '.' && r->uri.data[i - 1] != '/') { + r->exten.len = r->uri.len - i - 1; + + if (r->exten.len > 0) { + r->exten.data = ngx_palloc(r->pool, r->exten.len + 1); + if (r->exten.data == NULL) { + return NGX_ERROR; + } + + ngx_cpystrn(r->exten.data, &r->uri.data[i + 1], + r->exten.len + 1); + } + + break; + + } else if (r->uri.data[i] == '/') { + break; + } + } + + r->low_case_exten = 0; + + return NGX_OK; +} + + +ngx_int_t ngx_http_send_header(ngx_http_request_t *r) { if (r->err_status) { @@ -941,38 +976,29 @@ ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *in) } -ngx_int_t -ngx_http_set_exten(ngx_http_request_t *r) +u_char * +ngx_http_map_uri_to_path(ngx_http_request_t *r, ngx_str_t *path, + size_t reserved) { - ngx_int_t i; - - r->exten.len = 0; - r->exten.data = NULL; - - for (i = r->uri.len - 1; i > 1; i--) { - if (r->uri.data[i] == '.' && r->uri.data[i - 1] != '/') { - r->exten.len = r->uri.len - i - 1; + u_char *last; + size_t alias; + ngx_http_core_loc_conf_t *clcf; - if (r->exten.len > 0) { - r->exten.data = ngx_palloc(r->pool, r->exten.len + 1); - if (r->exten.data == NULL) { - return NGX_ERROR; - } + clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); - ngx_cpystrn(r->exten.data, &r->uri.data[i + 1], - r->exten.len + 1); - } + alias = clcf->alias ? clcf->name.len : 0; - break; + path->len = clcf->root.len + r->uri.len - alias + 1 + reserved; - } else if (r->uri.data[i] == '/') { - break; - } + path->data = ngx_palloc(r->pool, path->len); + if (path->data == NULL) { + return NULL; } - r->low_case_exten = 0; + last = ngx_cpymem(path->data, clcf->root.data, clcf->root.len); + last = ngx_cpystrn(last, r->uri.data + alias, r->uri.len - alias + 1); - return NGX_OK; + return last; } |