6 | 6 |
#include <ngx_config.h>
|
7 | 7 |
#include <ngx_core.h>
|
8 | 8 |
#include <ngx_http.h>
|
9 | |
#include "gd.h"
|
|
9 |
|
|
10 |
#include <gd.h>
|
10 | 11 |
|
11 | 12 |
|
12 | 13 |
#define NGX_HTTP_IMAGE_OFF 0
|
|
19 | 20 |
#define NGX_HTTP_IMAGE_START 0
|
20 | 21 |
#define NGX_HTTP_IMAGE_READ 1
|
21 | 22 |
#define NGX_HTTP_IMAGE_PROCESS 2
|
22 | |
#define NGX_HTTP_IMAGE_DONE 3
|
|
23 |
#define NGX_HTTP_IMAGE_PASS 3
|
|
24 |
#define NGX_HTTP_IMAGE_DONE 4
|
23 | 25 |
|
24 | 26 |
|
25 | 27 |
#define NGX_HTTP_IMAGE_NONE 0
|
|
54 | 56 |
} ngx_http_image_filter_ctx_t;
|
55 | 57 |
|
56 | 58 |
|
|
59 |
static ngx_int_t ngx_http_image_send(ngx_http_request_t *r,
|
|
60 |
ngx_http_image_filter_ctx_t *ctx, ngx_chain_t *in);
|
57 | 61 |
static ngx_uint_t ngx_http_image_test(ngx_http_request_t *r, ngx_chain_t *in);
|
58 | 62 |
static ngx_int_t ngx_http_image_read(ngx_http_request_t *r, ngx_chain_t *in);
|
59 | 63 |
static ngx_buf_t *ngx_http_image_process(ngx_http_request_t *r);
|
|
246 | 250 |
|
247 | 251 |
if (out.buf) {
|
248 | 252 |
out.next = NULL;
|
249 | |
in = &out;
|
250 | |
|
251 | |
break;
|
|
253 |
ctx->phase = NGX_HTTP_IMAGE_DONE;
|
|
254 |
|
|
255 |
return ngx_http_image_send(r, ctx, &out);
|
252 | 256 |
}
|
253 | 257 |
}
|
254 | 258 |
|
|
263 | 267 |
r->headers_out.content_type = *ct;
|
264 | 268 |
|
265 | 269 |
if (conf->filter == NGX_HTTP_IMAGE_TEST) {
|
266 | |
break;
|
|
270 |
ctx->phase = NGX_HTTP_IMAGE_PASS;
|
|
271 |
|
|
272 |
return ngx_http_image_send(r, ctx, in);
|
267 | 273 |
}
|
268 | 274 |
|
269 | 275 |
ctx->phase = NGX_HTTP_IMAGE_READ;
|
|
295 | 301 |
}
|
296 | 302 |
|
297 | 303 |
out.next = NULL;
|
298 | |
in = &out;
|
299 | |
|
300 | |
break;
|
|
304 |
ctx->phase = NGX_HTTP_IMAGE_PASS;
|
|
305 |
|
|
306 |
return ngx_http_image_send(r, ctx, &out);
|
|
307 |
|
|
308 |
case NGX_HTTP_IMAGE_PASS:
|
|
309 |
|
|
310 |
return ngx_http_next_body_filter(r, in);
|
301 | 311 |
|
302 | 312 |
default: /* NGX_HTTP_IMAGE_DONE */
|
303 | 313 |
|
304 | |
return ngx_http_next_body_filter(r, in);
|
305 | |
}
|
306 | |
|
307 | |
ctx->phase = NGX_HTTP_IMAGE_DONE;
|
|
314 |
rc = ngx_http_next_body_filter(r, NULL);
|
|
315 |
|
|
316 |
/* NGX_ERROR resets any pending data */
|
|
317 |
return (rc == NGX_OK) ? NGX_ERROR : rc;
|
|
318 |
}
|
|
319 |
}
|
|
320 |
|
|
321 |
|
|
322 |
static ngx_int_t
|
|
323 |
ngx_http_image_send(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx,
|
|
324 |
ngx_chain_t *in)
|
|
325 |
{
|
|
326 |
ngx_int_t rc;
|
308 | 327 |
|
309 | 328 |
rc = ngx_http_next_header_filter(r);
|
310 | 329 |
|
311 | 330 |
if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
|
312 | |
return rc;
|
313 | |
}
|
314 | |
|
315 | |
return ngx_http_next_body_filter(r, in);
|
|
331 |
return NGX_ERROR;
|
|
332 |
}
|
|
333 |
|
|
334 |
rc = ngx_http_next_body_filter(r, in);
|
|
335 |
|
|
336 |
if (ctx->phase == NGX_HTTP_IMAGE_DONE) {
|
|
337 |
/* NGX_ERROR resets any pending data */
|
|
338 |
return (rc == NGX_OK) ? NGX_ERROR : rc;
|
|
339 |
}
|
|
340 |
|
|
341 |
return rc;
|
316 | 342 |
}
|
317 | 343 |
|
318 | 344 |
|