fix ngx_http_send_special() for subrequests handled by perl
diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
index 57128a3..d60384f 100644
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -2694,7 +2694,13 @@
     }
 
     if (flags & NGX_HTTP_LAST) {
-        b->last_buf = 1;
+
+        if (r == r->main && !r->post_action) {
+            b->last_buf = 1;
+
+        } else {
+            b->last_in_chain = 1;
+        }
     }
 
     if (flags & NGX_HTTP_FLUSH) {
diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
index add5b21..cc303b4 100644
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -2888,7 +2888,7 @@
 
     r->connection->log->action = "sending to client";
 
-    if (rc == 0 && r == r->main && !r->post_action) {
+    if (rc == 0) {
         rc = ngx_http_send_special(r, NGX_HTTP_LAST);
     }