Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent spinning when progress is not being made. #100

Merged
merged 1 commit into from
Apr 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions filter/ngx_http_brotli_filter_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ static ngx_int_t ngx_http_brotli_body_filter(ngx_http_request_t* r,
int rc;
ngx_http_brotli_ctx_t* ctx;
size_t available_output;
ptrdiff_t available_busy_output;
size_t input_size;
size_t available_input;
const uint8_t* next_input_byte;
Expand Down Expand Up @@ -375,6 +376,12 @@ static ngx_int_t ngx_http_brotli_body_filter(ngx_http_request_t* r,
- if there is more input - push it to encoder */
for (;;) {
if (ctx->output_busy || ctx->output_ready) {
if (ctx->output_busy) {
available_busy_output = ngx_buf_size(ctx->out_buf);
} else {
available_busy_output = 0;
}

rc = ngx_http_next_body_filter(r,
ctx->output_ready ? ctx->out_chain : NULL);
if (ctx->output_ready) {
Expand All @@ -385,6 +392,11 @@ static ngx_int_t ngx_http_brotli_body_filter(ngx_http_request_t* r,
ctx->output_busy = 0;
}
if (rc == NGX_OK) {
if (ctx->output_busy &&
available_busy_output == ngx_buf_size(ctx->out_buf)) {
r->connection->buffered |= NGX_HTTP_BROTLI_BUFFERED;
return NGX_AGAIN;
}
continue;
} else if (rc == NGX_AGAIN) {
if (ctx->output_busy) {
Expand Down