comparison src/http/modules/ngx_http_proxy_module.c @ 4602:8036fc6af2df

Proxy: added ctx checking to input filters. The proxy module context may be NULL in case of filter finalization (e.g. by image_filter) followed by an internal redirect. This needs some better handling, but for now just check if ctx is still here.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 23 Apr 2012 10:40:01 +0000
parents 834049edae24
children 32030fa8cb14 05beaa2d87b3
comparison
equal deleted inserted replaced
4601:084137d883ec 4602:8036fc6af2df
1495 ngx_http_proxy_ctx_t *ctx; 1495 ngx_http_proxy_ctx_t *ctx;
1496 1496
1497 u = r->upstream; 1497 u = r->upstream;
1498 ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module); 1498 ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module);
1499 1499
1500 if (ctx == NULL) {
1501 return NGX_ERROR;
1502 }
1503
1500 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 1504 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1501 "http proxy filter init s:%d h:%d c:%d l:%O", 1505 "http proxy filter init s:%d h:%d c:%d l:%O",
1502 u->headers_in.status_n, ctx->head, u->headers_in.chunked, 1506 u->headers_in.status_n, ctx->head, u->headers_in.chunked,
1503 u->headers_in.content_length_n); 1507 u->headers_in.content_length_n);
1504 1508
1634 sw_trailer_header, 1638 sw_trailer_header,
1635 sw_trailer_header_almost_done 1639 sw_trailer_header_almost_done
1636 } state; 1640 } state;
1637 1641
1638 ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module); 1642 ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module);
1643
1644 if (ctx == NULL) {
1645 return NGX_ERROR;
1646 }
1647
1639 state = ctx->state; 1648 state = ctx->state;
1640 1649
1641 if (state == sw_chunk_data && ctx->size == 0) { 1650 if (state == sw_chunk_data && ctx->size == 0) {
1642 state = sw_after_data; 1651 state = sw_after_data;
1643 } 1652 }
1881 } 1890 }
1882 1891
1883 r = p->input_ctx; 1892 r = p->input_ctx;
1884 ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module); 1893 ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module);
1885 1894
1895 if (ctx == NULL) {
1896 return NGX_ERROR;
1897 }
1898
1886 b = NULL; 1899 b = NULL;
1887 prev = &buf->shadow; 1900 prev = &buf->shadow;
1888 1901
1889 for ( ;; ) { 1902 for ( ;; ) {
1890 1903
2062 ngx_chain_t *cl, **ll; 2075 ngx_chain_t *cl, **ll;
2063 ngx_http_upstream_t *u; 2076 ngx_http_upstream_t *u;
2064 ngx_http_proxy_ctx_t *ctx; 2077 ngx_http_proxy_ctx_t *ctx;
2065 2078
2066 ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module); 2079 ctx = ngx_http_get_module_ctx(r, ngx_http_proxy_module);
2080
2081 if (ctx == NULL) {
2082 return NGX_ERROR;
2083 }
2084
2067 u = r->upstream; 2085 u = r->upstream;
2068 buf = &u->buffer; 2086 buf = &u->buffer;
2069 2087
2070 buf->pos = buf->last; 2088 buf->pos = buf->last;
2071 buf->last += bytes; 2089 buf->last += bytes;