[RFC] [PATCH] Autoindex: support sorting using URL parameters

Peter Wu lekensteyn at gmail.com
Sat Feb 2 21:06:51 UTC 2013


Hi Valentin,

On Wednesday 30 January 2013 22:54:29 Valentin V. Bartenev wrote:
> I would prefer something like "autoindex_sort" directive
> 
>   autoindex_sort criterion [ order ];
> 
> with variables support.
> 
> And if user want Apache-like behavior then he will be able to configure
> it like this:
> 
>   map $arg_C   $criteria {
>       default  name;
>       M        modified;
>       S        size;
>   }
> 
>   map $arg_O   $ord {
>       default  asc;
>       D        desc;
>   }
> 
>   autoindex_sort $criteria $ord;

Can you give me some pointers on how to implement it? I am currently planning 
to use http://www.nginxguts.com/2011/01/working-with-cookies/ as guide for 
using variables, but I have seen some other possibilities (from a quick 
glance): using ngx_http_get_indexed_variable (described in a document from 
2008[1]).

My current idea is to:
1. Add two complex value types in ngx_http_autoindex_loc_conf_t, one for 
criteria, the other for order.
2. In the ngx_http_autoindex_handler function, evaluate the complex value. 
RFC: what should happen if the values are invalid? Simply ignore invalid sort 
criteria and orderings, defaulting to sorting by name in ascending order?
3. Store the resulting sort criteria and order in a struct with a pointer to 
it in ngx_http_autoindex_entry_t. (to avoid evaluating complex values for each 
qsort() call).

Thanks,
Peter

 [1]: http://antoine.bonavita.free.fr/nginx_mod_dev_en.html



More information about the nginx-devel mailing list