Skip to content

Commit

Permalink
Request tail of encoded data.
Browse files Browse the repository at this point in the history
Workflow before:
 * ...
 * consume last input buffer (pass to encoder)
 * pull output
 * check is finished (no)
 * no more input -> return

Workflow after:
 * ...
 * consume last input buffer (pass to encoder)
 * pull output
 * check finished (no)
 * no more input -> ask encoder to procees (since it is not finished)
 * pull output
 * check finished (yes) -> return
  • Loading branch information
eustas committed Sep 6, 2019
1 parent e7b3b3e commit b724875
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 b724875

Please sign in to comment.