diff --git a/README.rst b/README.rst index 18b69fd..080fb03 100644 --- a/README.rst +++ b/README.rst @@ -176,6 +176,19 @@ fancyindex_header .. note:: Using this directive needs the ngx_http_addition_module_ built into Nginx. +fancyindex_show_path +~~~~~~~~~~~~~~~~~ +:Syntax: *fancyindex_show_path* [*on* | *off*] +:Default: fancyindex_show_path on +:Context: http, server, location +:Description: + Whether to output or not the path and the closing tag after the header. + This is useful when you want to handle the path displaying with a PHP script + for example. + +.. warning:: This directive can be turned off only if a custom header is provided + using fancyindex_header. + fancyindex_ignore ~~~~~~~~~~~~~~~~~ :Syntax: *fancyindex_ignore string1 [string2 [... stringN]]* diff --git a/ngx_http_fancyindex_module.c b/ngx_http_fancyindex_module.c index 399b848..13dbd27 100644 --- a/ngx_http_fancyindex_module.c +++ b/ngx_http_fancyindex_module.c @@ -152,6 +152,7 @@ typedef struct { ngx_flag_t exact_size; /**< Sizes are sent always in bytes. */ ngx_uint_t name_length; /**< Maximum length of file names in bytes. */ ngx_flag_t hide_symlinks;/**< Hide symbolic links in listings. */ + ngx_flag_t show_path; /**< Whether to display or not the path + '' after the header */ ngx_str_t header; /**< File name for header, or empty if none. */ ngx_str_t footer; /**< File name for footer, or empty if none. */ @@ -339,6 +340,13 @@ static ngx_command_t ngx_http_fancyindex_commands[] = { offsetof(ngx_http_fancyindex_loc_conf_t, hide_symlinks), NULL }, + { ngx_string("fancyindex_show_path"), + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, + ngx_conf_set_flag_slot, + NGX_HTTP_LOC_CONF_OFFSET, + offsetof(ngx_http_fancyindex_loc_conf_t, show_path), + NULL }, + { ngx_string("fancyindex_time_format"), NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, ngx_conf_set_str_slot, @@ -711,13 +719,21 @@ make_content_buf( /* * Calculate needed buffer length. */ - len = r->uri.len - + ngx_sizeof_ssz(t05_body2) - + ngx_sizeof_ssz(t06_list1) - + ngx_sizeof_ssz(t_parentdir_entry) - + ngx_sizeof_ssz(t07_list2) - + ngx_fancyindex_timefmt_calc_size (&alcf->time_format) * entries.nelts - ; + if (alcf->show_path) + len = r->uri.len + + ngx_sizeof_ssz(t05_body2) + + ngx_sizeof_ssz(t06_list1) + + ngx_sizeof_ssz(t_parentdir_entry) + + ngx_sizeof_ssz(t07_list2) + + ngx_fancyindex_timefmt_calc_size (&alcf->time_format) * entries.nelts + ; + else + len = r->uri.len + + ngx_sizeof_ssz(t06_list1) + + ngx_sizeof_ssz(t_parentdir_entry) + + ngx_sizeof_ssz(t07_list2) + + ngx_fancyindex_timefmt_calc_size (&alcf->time_format) * entries.nelts + ; /* * If we are a the root of the webserver (URI = "/" --> length of 1), @@ -845,8 +861,13 @@ make_content_buf( sort_cmp_func); } - b->last = ngx_cpymem_str(b->last, r->uri); - b->last = ngx_cpymem_ssz(b->last, t05_body2); + /* Display the path, if needed */ + if (alcf->show_path){ + b->last = ngx_cpymem_str(b->last, r->uri); + b->last = ngx_cpymem_ssz(b->last, t05_body2); + } + + /* Open the