Brotli: send special buffers down the pipe.

Previously, special "flush" buffer was discarded if there was nothing
to flush from Brotli filter, which resulted in HTTP headers not being
flushed to the client in case of upstream read timeout.

This should have been included in 67d077a.

Change-Id: I9581a7bb6abeed12e5be7e0737c8899f97de4d20
Signed-off-by: Piotr Sikora <piotrsikora@google.com>
Reviewed-on: https://nginx-review.googlesource.com/1230
Reviewed-by: Martin Maly <mmaly@google.com>
diff --git a/src/ngx_http_brotli_filter_module.cc b/src/ngx_http_brotli_filter_module.cc
index 19da345..2a6406b 100644
--- a/src/ngx_http_brotli_filter_module.cc
+++ b/src/ngx_http_brotli_filter_module.cc
@@ -575,19 +575,29 @@
 
     if (ctx->last || ctx->flush) {
 
+        if (cl == NULL) {
+            cl = ngx_alloc_chain_link(r->pool);
+            if (cl == NULL) {
+                return NGX_ERROR;
+            }
+
+            cl->buf = reinterpret_cast<ngx_buf_t *>(ngx_calloc_buf(r->pool));
+            if (cl->buf == NULL) {
+                return NGX_ERROR;
+            }
+
+            cl->next = NULL;
+            *ctx->last_out = cl;
+            ctx->last_out = &cl->next;
+        }
+
         if (ctx->last) {
             ctx->done = 1;
-
-            if (cl) {
-                cl->buf->last_buf = 1;
-            }
+            cl->buf->last_buf = 1;
 
         } else if (ctx->flush) {
             ctx->flush = 0;
-
-            if (cl) {
-                cl->buf->flush = 1;
-            }
+            cl->buf->flush = 1;
         }
 
         r->connection->buffered &= ~NGX_HTTP_GZIP_BUFFERED;