[PATCH 4 of 4] Handle empty response body

Laurence Rowe l at lrowe.co.uk
Wed Mar 21 21:28:34 UTC 2012


# HG changeset patch
# User Laurence Rowe <laurence at lrowe.co.uk>
# Date 1332363819 0
# Node ID 1a21700079c90be39eaf5f6c5d7aef65be43ff95
# Parent  65fd4892a78371e863d43e31d4430cdb7333a35d
Handle empty response body

Responses, and especially proxied responses, may have empty bodies. These
should pass through the filter without causing an internal server error or
crashing nginx.

Example config:

    location = /testme {
        default_type text/xml;
        return 204;
        xslt_stylesheet example.xsl;
    }

diff --git a/src/http/modules/ngx_http_xslt_filter_module.c b/src/http/modules/ngx_http_xslt_filter_module.c
--- a/src/http/modules/ngx_http_xslt_filter_module.c
+++ b/src/http/modules/ngx_http_xslt_filter_module.c
@@ -284,10 +284,17 @@
 
         if (cl->buf->last_buf || cl->buf->last_in_chain) {
 
+            if (ctx->ctxt == NULL) {
+                /* empty body */
+                return ngx_http_next_header_filter(r);
+            }
+
             ctx->doc = ctx->ctxt->myDoc;
 
 #if (NGX_HTTP_XSLT_REUSE_DTD)
-            ctx->doc->extSubset = NULL;
+            if (ctx->doc) {
+                ctx->doc->extSubset = NULL;
+            }
 #endif
 
             wellFormed = ctx->ctxt->wellFormed;
@@ -377,6 +384,10 @@
 
     if (ctx->ctxt == NULL) {
 
+        if (b->last == b->pos) {
+            return NGX_OK;
+        }
+
         if (ctx->html_parser) {
             if (r->headers_out.charset.len) {
                 enc = xmlParseCharEncoding(



More information about the nginx-devel mailing list