diff options
Diffstat (limited to 'src/http/modules')
| -rw-r--r-- | src/http/modules/ngx_http_index_handler.c | 49 | ||||
| -rw-r--r-- | src/http/modules/ngx_http_static_handler.c | 42 |
2 files changed, 53 insertions, 38 deletions
diff --git a/src/http/modules/ngx_http_index_handler.c b/src/http/modules/ngx_http_index_handler.c index ddd889404..acfd30850 100644 --- a/src/http/modules/ngx_http_index_handler.c +++ b/src/http/modules/ngx_http_index_handler.c @@ -107,7 +107,8 @@ ngx_int_t ngx_http_index_handler(ngx_http_request_t *r) ngx_http_index_ctx_t *ctx; ngx_http_core_loc_conf_t *clcf; ngx_http_index_loc_conf_t *ilcf; -#if (NGX_HTTP_CACHE) +#if (NGX_HTTP_CACHE0) + /* crc must be in ctx !! */ uint32_t crc; #endif @@ -174,27 +175,17 @@ ngx_int_t ngx_http_index_handler(ngx_http_request_t *r) #endif if (clcf->alias) { - if (clcf->root.len > clcf->name.len) { - ctx->path.data = ngx_palloc(r->pool, clcf->root.len - + r->uri.len - - clcf->name.len - + ilcf->max_index_len); - if (ctx->path.data == NULL) { - return NGX_HTTP_INTERNAL_SERVER_ERROR; - } - - ctx->redirect.data = ctx->path.data + clcf->root.len + 1 - - clcf->name.len; - - } else { - ctx->redirect.data = ngx_palloc(r->pool, r->uri.len - + ilcf->max_index_len); - if (ctx->redirect.data == NULL) { - return NGX_HTTP_INTERNAL_SERVER_ERROR; - } + ctx->path.data = ngx_palloc(r->pool, clcf->root.len + + r->uri.len + 1 - clcf->name.len + + ilcf->max_index_len); + if (ctx->path.data == NULL) { + return NGX_HTTP_INTERNAL_SERVER_ERROR; + } - ctx->path.data = ctx->redirect.data + clcf->name.len - - clcf->root.len; + ctx->redirect.data = ngx_palloc(r->pool, r->uri.len + + ilcf->max_index_len); + if (ctx->redirect.data == NULL) { + return NGX_HTTP_INTERNAL_SERVER_ERROR; } ngx_memcpy(ctx->path.data, clcf->root.data, clcf->root.len); @@ -203,6 +194,7 @@ ngx_int_t ngx_http_index_handler(ngx_http_request_t *r) r->uri.data + clcf->name.len, r->uri.len + 1 - clcf->name.len); +#if 0 /* * aliases usually have trailling "/", * set it in the start of the possible redirect @@ -211,6 +203,7 @@ ngx_int_t ngx_http_index_handler(ngx_http_request_t *r) if (*ctx->redirect.data != '/') { ctx->redirect.data--; } +#endif } else { ctx->path.data = ngx_palloc(r->pool, clcf->root.len + r->uri.len @@ -241,6 +234,9 @@ ngx_int_t ngx_http_index_handler(ngx_http_request_t *r) name = ctx->path.data; } + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, + "open index \"%s\"", name); + fd = ngx_open_file(name, NGX_FILE_RDONLY, NGX_FILE_OPEN); if (fd == (ngx_fd_t) NGX_AGAIN) { @@ -250,8 +246,8 @@ ngx_int_t ngx_http_index_handler(ngx_http_request_t *r) if (fd == NGX_INVALID_FILE) { err = ngx_errno; - ngx_log_error(NGX_LOG_DEBUG, log, err, - "debug: " ngx_open_file_n " %s failed", name); + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, err, + ngx_open_file_n " %s failed", name); if (err == NGX_ENOTDIR) { return ngx_http_index_error(r, ctx, err); @@ -293,11 +289,12 @@ ngx_int_t ngx_http_index_handler(ngx_http_request_t *r) } else { if (clcf->alias) { - ngx_memcpy(ctx->redirect.data, clcf->name.data, clcf->name.len); + name = ngx_cpymem(ctx->redirect.data, r->uri.data, r->uri.len); + ngx_memcpy(name, index[ctx->index].data, + index[ctx->index].len + 1); } - ctx->redirect.len = r->uri.len + index[ctx->index].len - - clcf->alias * clcf->name.len; + ctx->redirect.len = r->uri.len + index[ctx->index].len; r->file.name.len = clcf->root.len + r->uri.len - clcf->alias * clcf->name.len + index[ctx->index].len; diff --git a/src/http/modules/ngx_http_static_handler.c b/src/http/modules/ngx_http_static_handler.c index bc32cc539..9a1a814ef 100644 --- a/src/http/modules/ngx_http_static_handler.c +++ b/src/http/modules/ngx_http_static_handler.c @@ -115,18 +115,27 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r) * in a possible redirect and for the last '\0' */ - name.data = ngx_palloc(r->pool, clcf->root.len + r->uri.len + 2 - - clcf->alias * clcf->name.len); - if (name.data == NULL) { - return NGX_HTTP_INTERNAL_SERVER_ERROR; - } - - location.data = ngx_cpymem(name.data, clcf->root.data, clcf->root.len); - if (clcf->alias) { - last = ngx_cpystrn(location.data, r->uri.data + clcf->name.len, + name.data = ngx_palloc(r->pool, clcf->root.len + r->uri.len + 2 + - clcf->name.len); + if (name.data == NULL) { + return NGX_HTTP_INTERNAL_SERVER_ERROR; + } + + last = ngx_cpymem(name.data, clcf->root.data, clcf->root.len); + last = ngx_cpystrn(last, r->uri.data + clcf->name.len, r->uri.len + 1 - clcf->name.len); + name.len = last - name.data; + + location.data = ngx_palloc(r->pool, r->uri.len + 2); + if (location.data == NULL) { + return NGX_HTTP_INTERNAL_SERVER_ERROR; + } + + last = ngx_cpystrn(location.data, r->uri.data, r->uri.len + 1); + +#if 0 /* * aliases usually have trailling "/", * set it in the start of the possible redirect @@ -135,13 +144,22 @@ static ngx_int_t ngx_http_static_handler(ngx_http_request_t *r) if (*location.data != '/') { location.data--; } +#endif + + location.len = last - location.data + 1; } else { + name.data = ngx_palloc(r->pool, clcf->root.len + r->uri.len + 2); + if (name.data == NULL) { + return NGX_HTTP_INTERNAL_SERVER_ERROR; + } + + location.data = ngx_cpymem(name.data, clcf->root.data, clcf->root.len); last = ngx_cpystrn(location.data, r->uri.data, r->uri.len + 1); - } - name.len = last - name.data; - location.len = last - location.data + 1; + name.len = last - name.data; + location.len = last - location.data + 1; + } ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, "http filename: \"%s\"", name.data); |
