]> git.kaiwu.me - nginx.git/commitdiff
allow to pass image filter errors via the same location where the filter is set
authorIgor Sysoev <igor@sysoev.ru>
Fri, 8 May 2009 14:52:50 +0000 (14:52 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Fri, 8 May 2009 14:52:50 +0000 (14:52 +0000)
src/http/modules/ngx_http_image_filter_module.c
src/http/modules/ngx_http_xslt_filter_module.c
src/http/ngx_http.h
src/http/ngx_http_special_response.c

index c68ecb510928fa8ea6ff998740965de25a55b85d..83fc1459ecbac85c422548afa1b48f5693ea360f 100644 (file)
@@ -181,6 +181,13 @@ ngx_http_image_header_filter(ngx_http_request_t *r)
         return NGX_ERROR;
     }
 
+    ctx = ngx_http_get_module_ctx(r, ngx_http_image_filter_module);
+
+    if (ctx) {
+        ngx_http_set_ctx(r, NULL, ngx_http_image_filter_module);
+        return ngx_http_next_header_filter(r);
+    }
+
     ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_image_filter_ctx_t));
     if (ctx == NULL) {
         return NGX_ERROR;
@@ -258,6 +265,7 @@ ngx_http_image_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
             }
 
             return ngx_http_filter_finalize_request(r,
+                                              &ngx_http_image_filter_module,
                                               NGX_HTTP_UNSUPPORTED_MEDIA_TYPE);
         }
 
@@ -287,6 +295,7 @@ ngx_http_image_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
 
         if (rc == NGX_ERROR) {
             return ngx_http_filter_finalize_request(r,
+                                              &ngx_http_image_filter_module,
                                               NGX_HTTP_UNSUPPORTED_MEDIA_TYPE);
         }
 
@@ -298,6 +307,7 @@ ngx_http_image_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
 
         if (out.buf == NULL) {
             return ngx_http_filter_finalize_request(r,
+                                              &ngx_http_image_filter_module,
                                               NGX_HTTP_UNSUPPORTED_MEDIA_TYPE);
         }
 
index 4759308c2c9ef301de9ca4cc371504f9934f2cd8..220400c83b0149617fc11412800205ecea805f0e 100644 (file)
@@ -319,7 +319,7 @@ ngx_http_xslt_send(ngx_http_request_t *r, ngx_http_xslt_filter_ctx_t *ctx,
     ctx->done = 1;
 
     if (b == NULL) {
-        return ngx_http_filter_finalize_request(r,
+        return ngx_http_filter_finalize_request(r, NULL,
                                                NGX_HTTP_INTERNAL_SERVER_ERROR);
     }
 
@@ -327,7 +327,7 @@ ngx_http_xslt_send(ngx_http_request_t *r, ngx_http_xslt_filter_ctx_t *ctx,
 
     if (cln == NULL) {
         ngx_free(b->pos);
-        return ngx_http_filter_finalize_request(r,
+        return ngx_http_filter_finalize_request(r, NULL,
                                                NGX_HTTP_INTERNAL_SERVER_ERROR);
     }
 
index 2c442be9fe020f87c543365956d1c009dbf73597..9444b11319385e2d463313af4385f4ed2107685c 100644 (file)
@@ -104,7 +104,7 @@ ngx_int_t ngx_http_send_header(ngx_http_request_t *r);
 ngx_int_t ngx_http_special_response_handler(ngx_http_request_t *r,
     ngx_int_t error);
 ngx_int_t ngx_http_filter_finalize_request(ngx_http_request_t *r,
-    ngx_int_t error);
+    ngx_module_t *m, ngx_int_t error);
 void ngx_http_clean_header(ngx_http_request_t *r);
 
 
index 8f0a2078d3eb8d199517d0b274b43f639712bb5d..9bf99162b62dda6b07690de2dfcaf80f1ba10f7a 100644 (file)
@@ -446,15 +446,25 @@ ngx_http_special_response_handler(ngx_http_request_t *r, ngx_int_t error)
 
 
 ngx_int_t
-ngx_http_filter_finalize_request(ngx_http_request_t *r, ngx_int_t error)
+ngx_http_filter_finalize_request(ngx_http_request_t *r, ngx_module_t *m,
+    ngx_int_t error)
 {
-    ngx_int_t  rc;
+    void       *ctx;
+    ngx_int_t   rc;
 
     ngx_http_clean_header(r);
 
+    if (m) {
+        ctx = r->ctx[m->ctx_index];
+    }
+
     /* clear the modules contexts */
     ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);
 
+    if (m) {
+        r->ctx[m->ctx_index] = ctx;
+    }
+
     r->filter_finalize = 1;
 
     rc = ngx_http_special_response_handler(r, error);