Needs more love in the resolution of URI -> path

pull/4/head
Adrian Perez 2007-09-06 14:20:48 +02:00
parent 9a22652366
commit 3bfd1094a5
2 changed files with 34 additions and 9 deletions

View File

@ -13,21 +13,25 @@
ngx_buf_t* nfi_inline_getbuf(ngx_http_request_t *r,
const ngx_str_t const * path, ngx_int_t mode)
{
size_t root;
u_char *last;
ngx_str_t resolved;
ngx_buf_t *buf;
ngx_file_t *bfile;
ngx_file_info_t bfileinfo;
resolved.len = path->len;
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http nfi_inline_getbuf path: \"%V\"", path);
resolved.len = r->uri.len + path->len;
resolved.data = ngx_palloc(r->pool, resolved.len + 1);
if (resolved.data == NULL)
return NULL;
last = ngx_http_map_uri_to_path(r, &resolved, &root, 0);
if (last == NULL)
return NULL;
ngx_memcpy(
ngx_cpymem(resolved.data, r->uri.data, r->uri.len),
path->data, path->len);
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http nfi_inline_getbuf resolved: \"%V\"", &resolved);
/*
* Append final '\0' so we can use it to call ngx_file_info() below.
@ -39,8 +43,12 @@ ngx_buf_t* nfi_inline_getbuf(ngx_http_request_t *r,
* first.
*/
resolved.data[resolved.len] = '\0';
if (ngx_file_info(resolved.data, &bfileinfo) != 0)
if (ngx_file_info(resolved.data, &bfileinfo) != 0) {
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, ngx_errno,
"http nfi_inline_getbuf no file stats");
return NULL;
}
if (!ngx_is_file(&bfileinfo) || /* we read regular files... */
!(ngx_file_access(&bfileinfo) & 0444) /* ...which can be read... */
@ -81,6 +89,9 @@ ngx_buf_t* nfi_inline_getbuf(ngx_http_request_t *r,
*/
buf->file_last = ngx_file_size(&bfileinfo) - 1;
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"nfi_inline_getbuf returned buf %p", buf);
return buf;
}

View File

@ -19,11 +19,13 @@
* Distributed under terms of the BSD license.
*/
#include "ngx_http_fancyindex_module.h"
#include "template.h"
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>
#include "ngx_http_fancyindex_module.h"
#include "template.h"
#include <ngx_log.h>
#if 0
@ -189,6 +191,8 @@ ngx_http_fancyindex_handler(ngx_http_request_t *r)
ngx_tm_t tm;
ngx_err_t err;
ngx_buf_t *b;
ngx_buf_t *bheader = NULL;
ngx_buf_t *bfooter = NULL;
ngx_int_t rc, size;
ngx_str_t path;
ngx_str_t readme_path;
@ -384,6 +388,16 @@ ngx_http_fancyindex_handler(ngx_http_request_t *r)
ngx_close_dir_n " \"%s\" failed", &path);
}
/*
* Try to get header and footer, if enabled.
*/
if (alcf->header.len > 0) {
bheader = nfi_inline_getbuf(r, &alcf->header, alcf->include_mode);
}
if (alcf->footer.len > 0) {
bfooter = nfi_inline_getbuf(r, &alcf->footer, alcf->include_mode);
}
len = NFI_TEMPLATE_SIZE
+ r->uri.len /* URI is included two times: as <title> in the */
+ r->uri.len /* HTML head and as an <h1> in the HTML body */