diff options
| author | Igor Sysoev <igor@sysoev.ru> | 2009-05-08 14:25:51 +0000 |
|---|---|---|
| committer | Igor Sysoev <igor@sysoev.ru> | 2009-05-08 14:25:51 +0000 |
| commit | fd4191845b62a9bc7ad0cf23d6e64866dbc5e0f6 (patch) | |
| tree | c7ff251d2c11da5aea16f3780cdb39fed1c1efc1 /src/http/modules | |
| parent | 4318688cce5dc30a2db7bfe1a734e1ff6782e7f9 (diff) | |
| download | nginx-fd4191845b62a9bc7ad0cf23d6e64866dbc5e0f6.tar.gz nginx-fd4191845b62a9bc7ad0cf23d6e64866dbc5e0f6.tar.bz2 | |
handle big responses for "size" and "test" image_filters
Diffstat (limited to 'src/http/modules')
| -rw-r--r-- | src/http/modules/ngx_http_image_filter_module.c | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/src/http/modules/ngx_http_image_filter_module.c b/src/http/modules/ngx_http_image_filter_module.c index 10fefc549..c68ecb510 100644 --- a/src/http/modules/ngx_http_image_filter_module.c +++ b/src/http/modules/ngx_http_image_filter_module.c @@ -7,7 +7,8 @@ #include <ngx_config.h> #include <ngx_core.h> #include <ngx_http.h> -#include "gd.h" + +#include <gd.h> #define NGX_HTTP_IMAGE_OFF 0 @@ -20,7 +21,8 @@ #define NGX_HTTP_IMAGE_START 0 #define NGX_HTTP_IMAGE_READ 1 #define NGX_HTTP_IMAGE_PROCESS 2 -#define NGX_HTTP_IMAGE_DONE 3 +#define NGX_HTTP_IMAGE_PASS 3 +#define NGX_HTTP_IMAGE_DONE 4 #define NGX_HTTP_IMAGE_NONE 0 @@ -55,6 +57,8 @@ typedef struct { } ngx_http_image_filter_ctx_t; +static ngx_int_t ngx_http_image_send(ngx_http_request_t *r, + ngx_http_image_filter_ctx_t *ctx, ngx_chain_t *in); static ngx_uint_t ngx_http_image_test(ngx_http_request_t *r, ngx_chain_t *in); static ngx_int_t ngx_http_image_read(ngx_http_request_t *r, ngx_chain_t *in); static ngx_buf_t *ngx_http_image_process(ngx_http_request_t *r); @@ -247,9 +251,9 @@ ngx_http_image_body_filter(ngx_http_request_t *r, ngx_chain_t *in) if (out.buf) { out.next = NULL; - in = &out; + ctx->phase = NGX_HTTP_IMAGE_DONE; - break; + return ngx_http_image_send(r, ctx, &out); } } @@ -264,7 +268,9 @@ ngx_http_image_body_filter(ngx_http_request_t *r, ngx_chain_t *in) r->headers_out.content_type = *ct; if (conf->filter == NGX_HTTP_IMAGE_TEST) { - break; + ctx->phase = NGX_HTTP_IMAGE_PASS; + + return ngx_http_image_send(r, ctx, in); } ctx->phase = NGX_HTTP_IMAGE_READ; @@ -296,24 +302,44 @@ ngx_http_image_body_filter(ngx_http_request_t *r, ngx_chain_t *in) } out.next = NULL; - in = &out; + ctx->phase = NGX_HTTP_IMAGE_PASS; - break; + return ngx_http_image_send(r, ctx, &out); - default: /* NGX_HTTP_IMAGE_DONE */ + case NGX_HTTP_IMAGE_PASS: return ngx_http_next_body_filter(r, in); + + default: /* NGX_HTTP_IMAGE_DONE */ + + rc = ngx_http_next_body_filter(r, NULL); + + /* NGX_ERROR resets any pending data */ + return (rc == NGX_OK) ? NGX_ERROR : rc; } +} + - ctx->phase = NGX_HTTP_IMAGE_DONE; +static ngx_int_t +ngx_http_image_send(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx, + ngx_chain_t *in) +{ + ngx_int_t rc; rc = ngx_http_next_header_filter(r); if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) { - return rc; + return NGX_ERROR; + } + + rc = ngx_http_next_body_filter(r, in); + + if (ctx->phase == NGX_HTTP_IMAGE_DONE) { + /* NGX_ERROR resets any pending data */ + return (rc == NGX_OK) ? NGX_ERROR : rc; } - return ngx_http_next_body_filter(r, in); + return rc; } |
