Last active
August 29, 2015 14:21
-
-
Save altexy/2e5a3f7737d3d5c58b00 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static ngx_int_t my_http_body_filter(ngx_http_request_t *r, ngx_chain_t *in) | |
{ | |
ngx_int_t rc; | |
ngx_uint_t last; | |
ngx_chain_t *cl; | |
ngx_http_request_t *sr; | |
ngx_str_t uri = SOME_INTERNAL_URI; | |
if (in == NULL || r->header_only ) { | |
return ngx_http_next_body_filter(r, in); | |
} | |
/* check is it last chunk */ | |
/* http://www.evanmiller.org/nginx-modules-guide.html#filters-body */ | |
last = 0; | |
for (cl = in; cl; cl = cl->next) { | |
if (cl->buf->last_buf) { | |
cl->buf->last_buf = 0; | |
cl->buf->sync = 1; | |
last = 1; | |
} | |
rc = ngx_http_next_body_filter(r, in); | |
if (rc == NGX_ERROR || rc > NGX_OK || !last) { | |
return rc; | |
} | |
if (r != r->main) { | |
/* we are processing a subrequest */ | |
return rc | |
} | |
if (ngx_http_subrequest(r, &uri, NULL, &sr, NULL, 0) != NGX_OK) { | |
/* the big difference with Evan's tutorial */ | |
/* but this is usual pattern in some modern modules */ | |
return NGX_ERROR; | |
} | |
return NGX_AGAIN; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment