Skip to content

Commit

Permalink
Merge pull request #83 from google/fix_tail
Browse files Browse the repository at this point in the history
Request tail of encoded data.
  • Loading branch information
eustas authored Sep 7, 2019
2 parents e7b3b3e + b724875 commit f76e882
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions filter/ngx_http_brotli_filter_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,14 +417,13 @@ static ngx_int_t ngx_http_brotli_body_filter(ngx_http_request_t* r,
ctx->bytes_out += available_output;
ctx->out_buf->last_buf = 0;
ctx->out_buf->flush = 0;
if (ctx->end_of_input) {
if (ctx->end_of_input && BrotliEncoderIsFinished(ctx->encoder)) {
ctx->out_buf->last_buf = 1;
r->connection->buffered &= ~NGX_HTTP_BROTLI_BUFFERED;
} else if (ctx->end_of_block) {
ctx->out_buf->flush = 1;
r->connection->buffered &= ~NGX_HTTP_BROTLI_BUFFERED;
}
ctx->end_of_input = 0;
ctx->end_of_block = 0;
ctx->output_ready = 1;
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
Expand All @@ -440,6 +439,21 @@ static ngx_int_t ngx_http_brotli_body_filter(ngx_http_request_t* r,
return NGX_OK;
}

if (ctx->end_of_input) {
// Ask the encoder to dump the leftover.
available_input = 0;
available_output = 0;
ok = BrotliEncoderCompressStream(ctx->encoder, BROTLI_OPERATION_FINISH,
&available_input, NULL,
&available_output, NULL, NULL);
r->connection->buffered |= NGX_HTTP_BROTLI_BUFFERED;
if (!ok) {
ngx_http_brotli_filter_close(ctx);
return NGX_ERROR;
}
continue;
}

if (ctx->in == NULL) {
return NGX_OK;
}
Expand Down

0 comments on commit f76e882

Please sign in to comment.