@@ -196,7 +196,7 @@ ngx_http_zstd_header_filter(ngx_http_request_t *r)
196196 || (r -> headers_out .content_encoding
197197 && r -> headers_out .content_encoding -> value .len )
198198 || (r -> headers_out .content_length_n != -1
199- && r -> headers_out .content_length_n > zlcf -> min_length )
199+ && r -> headers_out .content_length_n < zlcf -> min_length )
200200 || ngx_http_test_content_type (r , & zlcf -> types ) == NULL
201201 || r -> header_only )
202202 {
@@ -222,6 +222,7 @@ ngx_http_zstd_header_filter(ngx_http_request_t *r)
222222 ngx_http_set_ctx (r , ctx , ngx_http_zstd_filter_module );
223223
224224 ctx -> request = r ;
225+ ctx -> last_out = & ctx -> out ;
225226
226227 h = ngx_list_push (& r -> headers_out .headers );
227228 if (h == NULL ) {
@@ -401,15 +402,18 @@ ngx_http_zstd_filter_compress(ngx_http_request_t *r, ngx_http_zstd_ctx_t *ctx)
401402 case NGX_HTTP_ZSTD_FILTER_FLUSH :
402403 hint = "ZSTD_flushStream() " ;
403404 rc = ZSTD_flushStream (ctx -> cstream , & ctx -> buffer_out );
405+ break ;
404406
405407 case NGX_HTTP_ZSTD_FILTER_END :
406408 hint = "ZSTD_endStream() " ;
407409 rc = ZSTD_endStream (ctx -> cstream , & ctx -> buffer_out );
410+ break ;
408411
409412 default :
410413 hint = "ZSTD_compressStream() " ;
411414 rc = ZSTD_compressStream (ctx -> cstream , & ctx -> buffer_out ,
412415 & ctx -> buffer_in );
416+ break ;
413417 }
414418
415419 if (ZSTD_isError (rc )) {
@@ -448,6 +452,10 @@ ngx_http_zstd_filter_compress(ngx_http_request_t *r, ngx_http_zstd_ctx_t *ctx)
448452 ctx -> action = NGX_HTTP_ZSTD_FILTER_COMPRESS ; /* restore */
449453 }
450454
455+ if (ngx_buf_size (ctx -> out_buf ) == 0 ) {
456+ return NGX_AGAIN ;
457+ }
458+
451459 cl = ngx_alloc_chain_link (r -> pool );
452460 if (cl == NULL ) {
453461 return NGX_ERROR ;
@@ -471,6 +479,8 @@ ngx_http_zstd_filter_compress(ngx_http_request_t *r, ngx_http_zstd_ctx_t *ctx)
471479 * ctx -> last_out = cl ;
472480 ctx -> last_out = & cl -> next ;
473481
482+ ngx_memzero (& ctx -> buffer_out , sizeof (ZSTD_outBuffer ));
483+
474484 return ctx -> last && rc == 0 ? NGX_OK : NGX_AGAIN ;
475485}
476486
@@ -552,7 +562,7 @@ ngx_http_zstd_filter_get_buf(ngx_http_request_t *r, ngx_http_zstd_ctx_t *ctx)
552562
553563 ctx -> buffer_out .dst = ctx -> out_buf -> pos ;
554564 ctx -> buffer_out .pos = 0 ;
555- ctx -> buffer_out .size = ngx_buf_size ( ctx -> out_buf ) ;
565+ ctx -> buffer_out .size = ctx -> out_buf -> end - ctx -> out_buf -> start ;
556566
557567 return NGX_OK ;
558568}
@@ -749,6 +759,10 @@ ngx_http_zstd_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
749759 ngx_file_info_t info ;
750760 ngx_http_zstd_main_conf_t * zmcf ;
751761
762+ rc = NGX_OK ;
763+ buf = NULL ;
764+ fd = NGX_INVALID_FILE ;
765+
752766 ngx_conf_merge_value (conf -> enable , prev -> enable , 0 );
753767 ngx_conf_merge_value (conf -> level , prev -> level , 1 );
754768 ngx_conf_merge_value (conf -> min_length , prev -> min_length , 20 );
@@ -764,10 +778,6 @@ ngx_http_zstd_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
764778 ngx_conf_merge_bufs_value (conf -> bufs , prev -> bufs ,
765779 (128 * 1024 ) / ngx_pagesize , ngx_pagesize );
766780
767- rc = NGX_OK ;
768- buf = NULL ;
769- fd = -1 ;
770-
771781 zmcf = ngx_http_conf_get_module_main_conf (cf , ngx_http_zstd_filter_module );
772782
773783 if (conf -> enable && zmcf -> dict_file ) {
0 commit comments