proxying from pipes

Jeff Kaufman jefftk at
Tue Oct 23 15:14:52 UTC 2012

My module wants to sit in the filter chain passing buffers to an
asynchronous optimization thread and then send them out to the user
when they finish.  When a request comes in I have my module roughly

body filter:
 - if first set of buffers
   - create pipe, pass pipe_write_fd to optimization thread
 - pass all input data to optimization thread
 - don't call ngx_http_next_body_filter

Is there a way I can ask nginx to watch this pipe and treat any data
appearing on the pipe as if it is output from my body filter?  Passing
it through ngx_http_next_body_filter, etc?  And finalizing the request
if there's a problem with the pipe?

What I'm doing now is:
 - when creating the pipe
     c = ngx_get_connection(pipe_read_fd, r->connection->log);>handler = my_read_handler;
     ngx_add_event(c->read, NGX_READ_EVENT, 0);
 - when my_read_handler is called
     read() from pipe_read_fd
     create buffer, chain link
     call ngx_http_next_body_filter

Is this the right way to go about this?  It seems very low level and I
would expect proxying from a pipe would be something nginx already

Another option would be to simply use the pipe for notification and
load the data from the optimization thread through shared memory.


More information about the nginx-devel mailing list