Add auto Option to autoindex module

Valentin V. Bartenev vbart at nginx.com
Wed Nov 30 10:23:40 UTC 2016


On Tuesday 29 November 2016 21:36:27 Aaron U'Ren wrote:
> I recently came across the need to have multiple formats returned from the
> autoindex module based on the client. When a human hits the index page I
> needed it returned in HTML format. However, when an application fetched the
> index page it was much simpler for it to digest and parse JSON or XML. With
> the current autoindex module you could only specify a single format in the
> configuration.
> 
> It occurred to me that it might sometimes be better to have an option to
> allow the user agent to choose what format it wanted from the autoindex
> module rather than it being defined statically by the server's
> configuration. So I made a small patch that introduces a 5th "auto" option
> in addition to html, json, jsonp, and xml.

This should be implemented by adding support for variables in the directive.


> 
> With this option enabled the nginx server reads the "Accept" header from
> the user agent's request and if it is able to satisfy the format it will
> send the response in that format. Otherwise it will gracefully fall back to
> serving the response in the default html format.
> 
> Fair warning, my C is pretty rusty and I'm not at all that familiar with
> the nginx code base, but I was able to put together and successfully test
> the following patch on my machine.
> 
> Let me know what you guys think.
> 
[..]

Please check specification for the Accept header.  It provides much richer 
semantics than what you test.

  wbr, Valentin V. Bartenev



More information about the nginx-devel mailing list