quick start on writing a module?

Mark Harrison mh at pixar.com
Wed Jun 16 13:29:43 MSD 2010


I'd like to convert an apache module I've written to work
under nginx.  Can somebody loan me a clue for getting started?


Background
----------

The logic is pretty simple:

   1.  based on the input URI, determine what file will be
       sent.  this will possibly involved a (cached) db lookup.

   2a. set these headers:

         Content-disposition:
         ETag:
         X-mod_asset-version: (my custom header)

   2b. set mime type.

   3.  allow nginx to send the bytes of the file.  Hopefully
       it will handle these headers:

         Last-Modified:
         Content-Length:
         Accept-Ranges:
         Content-Range:
         Content-Length:

Questions
---------


For 2b, this is the proper way?

     r->headers_out.content_type.len = sizeof("image/gif") - 1;
     r->headers_out.content_type.data = (u_char *) "image/gif";

     Is there a special way to malloc the .data so that it
     will be freed automatically when the request is complete?


For 3, should I be using X-Accel-Redirect?

     add_header("X-Accel-Redirect: /protected/iso.img");

If so, then I can simply set my headers and pass along to the next
phase?

Any simple example modules I can use as a starting point?


Many TIA!!
Mark

-- 
Mark Harrison
Pixar Animation Studios



More information about the nginx mailing list