@@ -43,6 +43,7 @@ typedef struct {
4343 ngx_chain_t * out ;
4444 ngx_chain_t * * last_out ;
4545
46+ ngx_buf_t * in_buf ;
4647 ngx_buf_t * out_buf ;
4748 ngx_int_t bufs ;
4849
@@ -383,7 +384,7 @@ ngx_http_zstd_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
383384static ngx_int_t
384385ngx_http_zstd_filter_compress (ngx_http_request_t * r , ngx_http_zstd_ctx_t * ctx )
385386{
386- size_t rc , pos ;
387+ size_t rc , pos_in , pos_out ;
387388 char * hint ;
388389 ngx_chain_t * cl ;
389390 ngx_buf_t * b ;
@@ -395,7 +396,8 @@ ngx_http_zstd_filter_compress(ngx_http_request_t *r, ngx_http_zstd_ctx_t *ctx)
395396 ctx -> buffer_out .dst , ctx -> buffer_out .pos ,
396397 ctx -> buffer_out .size , ctx -> flush , ctx -> redo );
397398
398- pos = ctx -> buffer_out .pos ;
399+ pos_in = ctx -> buffer_in .pos ;
400+ pos_out = ctx -> buffer_out .pos ;
399401
400402 switch (ctx -> action ) {
401403
@@ -430,7 +432,8 @@ ngx_http_zstd_filter_compress(ngx_http_request_t *r, ngx_http_zstd_ctx_t *ctx)
430432 ctx -> buffer_out .dst , ctx -> buffer_out .pos ,
431433 ctx -> buffer_out .size );
432434
433- ctx -> out_buf -> last += ctx -> buffer_out .pos - pos ;
435+ ctx -> in_buf -> pos += ctx -> buffer_in .pos - pos_in ;
436+ ctx -> out_buf -> last += ctx -> buffer_out .pos - pos_out ;
434437 ctx -> redo = 0 ;
435438
436439 if (rc > 0 ) {
@@ -488,8 +491,6 @@ ngx_http_zstd_filter_compress(ngx_http_request_t *r, ngx_http_zstd_ctx_t *ctx)
488491static ngx_int_t
489492ngx_http_zstd_filter_add_data (ngx_http_request_t * r , ngx_http_zstd_ctx_t * ctx )
490493{
491- ngx_buf_t * buf ;
492-
493494 if (ctx -> buffer_in .pos < ctx -> buffer_in .size
494495 || ctx -> flush
495496 || ctx -> last
@@ -505,19 +506,19 @@ ngx_http_zstd_filter_add_data(ngx_http_request_t *r, ngx_http_zstd_ctx_t *ctx)
505506 return NGX_DECLINED ;
506507 }
507508
508- buf = ctx -> in -> buf ;
509+ ctx -> in_buf = ctx -> in -> buf ;
509510 ctx -> in = ctx -> in -> next ;
510511
511- if (buf -> flush ) {
512+ if (ctx -> in_buf -> flush ) {
512513 ctx -> flush = 1 ;
513514
514- } else if (buf -> last_buf ) {
515+ } else if (ctx -> in_buf -> last_buf ) {
515516 ctx -> last = 1 ;
516517 }
517518
518- ctx -> buffer_in .src = buf -> pos ;
519+ ctx -> buffer_in .src = ctx -> in_buf -> pos ;
519520 ctx -> buffer_in .pos = 0 ;
520- ctx -> buffer_in .size = ngx_buf_size (buf );
521+ ctx -> buffer_in .size = ngx_buf_size (ctx -> in_buf );
521522
522523 if (ctx -> buffer_in .size == 0 ) {
523524 return NGX_AGAIN ;
0 commit comments