@@ -55,44 +55,23 @@ typedef struct {
55
55
unsigned redo :1 ;
56
56
unsigned done :1 ;
57
57
unsigned nomem :1 ;
58
- unsigned gzheader :1 ;
59
58
unsigned buffering :1 ;
60
59
unsigned intel :1 ;
61
60
62
61
size_t zin ;
63
62
size_t zout ;
64
63
65
- uint32_t crc32 ;
66
64
z_stream zstream ;
67
65
ngx_http_request_t * request ;
68
66
} ngx_http_gzip_ctx_t ;
69
67
70
68
71
- #if (NGX_HAVE_LITTLE_ENDIAN && NGX_HAVE_NONALIGNED )
72
-
73
- struct gztrailer {
74
- uint32_t crc32 ;
75
- uint32_t zlen ;
76
- };
77
-
78
- #else /* NGX_HAVE_BIG_ENDIAN || !NGX_HAVE_NONALIGNED */
79
-
80
- struct gztrailer {
81
- u_char crc32 [4 ];
82
- u_char zlen [4 ];
83
- };
84
-
85
- #endif
86
-
87
-
88
69
static void ngx_http_gzip_filter_memory (ngx_http_request_t * r ,
89
70
ngx_http_gzip_ctx_t * ctx );
90
71
static ngx_int_t ngx_http_gzip_filter_buffer (ngx_http_gzip_ctx_t * ctx ,
91
72
ngx_chain_t * in );
92
73
static ngx_int_t ngx_http_gzip_filter_deflate_start (ngx_http_request_t * r ,
93
74
ngx_http_gzip_ctx_t * ctx );
94
- static ngx_int_t ngx_http_gzip_filter_gzheader (ngx_http_request_t * r ,
95
- ngx_http_gzip_ctx_t * ctx );
96
75
static ngx_int_t ngx_http_gzip_filter_add_data (ngx_http_request_t * r ,
97
76
ngx_http_gzip_ctx_t * ctx );
98
77
static ngx_int_t ngx_http_gzip_filter_get_buf (ngx_http_request_t * r ,
@@ -446,12 +425,6 @@ ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
446
425
return ctx -> busy ? NGX_AGAIN : NGX_OK ;
447
426
}
448
427
449
- if (!ctx -> gzheader ) {
450
- if (ngx_http_gzip_filter_gzheader (r , ctx ) != NGX_OK ) {
451
- goto failed ;
452
- }
453
- }
454
-
455
428
rc = ngx_http_next_body_filter (r , ctx -> out );
456
429
457
430
if (rc == NGX_ERROR ) {
@@ -643,7 +616,7 @@ ngx_http_gzip_filter_deflate_start(ngx_http_request_t *r,
643
616
ctx -> zstream .opaque = ctx ;
644
617
645
618
rc = deflateInit2 (& ctx -> zstream , (int ) conf -> level , Z_DEFLATED ,
646
- - ctx -> wbits , ctx -> memlevel , Z_DEFAULT_STRATEGY );
619
+ ctx -> wbits + 16 , ctx -> memlevel , Z_DEFAULT_STRATEGY );
647
620
648
621
if (rc != Z_OK ) {
649
622
ngx_log_error (NGX_LOG_ALERT , r -> connection -> log , 0 ,
@@ -652,45 +625,12 @@ ngx_http_gzip_filter_deflate_start(ngx_http_request_t *r,
652
625
}
653
626
654
627
ctx -> last_out = & ctx -> out ;
655
- ctx -> crc32 = crc32 (0L , Z_NULL , 0 );
656
628
ctx -> flush = Z_NO_FLUSH ;
657
629
658
630
return NGX_OK ;
659
631
}
660
632
661
633
662
- static ngx_int_t
663
- ngx_http_gzip_filter_gzheader (ngx_http_request_t * r , ngx_http_gzip_ctx_t * ctx )
664
- {
665
- ngx_buf_t * b ;
666
- ngx_chain_t * cl ;
667
- static u_char gzheader [10 ] =
668
- { 0x1f , 0x8b , Z_DEFLATED , 0 , 0 , 0 , 0 , 0 , 0 , 3 };
669
-
670
- b = ngx_calloc_buf (r -> pool );
671
- if (b == NULL ) {
672
- return NGX_ERROR ;
673
- }
674
-
675
- b -> memory = 1 ;
676
- b -> pos = gzheader ;
677
- b -> last = b -> pos + 10 ;
678
-
679
- cl = ngx_alloc_chain_link (r -> pool );
680
- if (cl == NULL ) {
681
- return NGX_ERROR ;
682
- }
683
-
684
- cl -> buf = b ;
685
- cl -> next = ctx -> out ;
686
- ctx -> out = cl ;
687
-
688
- ctx -> gzheader = 1 ;
689
-
690
- return NGX_OK ;
691
- }
692
-
693
-
694
634
static ngx_int_t
695
635
ngx_http_gzip_filter_add_data (ngx_http_request_t * r , ngx_http_gzip_ctx_t * ctx )
696
636
{
@@ -743,14 +683,9 @@ ngx_http_gzip_filter_add_data(ngx_http_request_t *r, ngx_http_gzip_ctx_t *ctx)
743
683
744
684
} else if (ctx -> in_buf -> flush ) {
745
685
ctx -> flush = Z_SYNC_FLUSH ;
746
- }
747
-
748
- if (ctx -> zstream .avail_in ) {
749
686
750
- ctx -> crc32 = crc32 (ctx -> crc32 , ctx -> zstream .next_in ,
751
- ctx -> zstream .avail_in );
752
-
753
- } else if (ctx -> flush == Z_NO_FLUSH ) {
687
+ } else if (ctx -> zstream .avail_in == 0 ) {
688
+ /* ctx->flush == Z_NO_FLUSH */
754
689
return NGX_AGAIN ;
755
690
}
756
691
@@ -932,13 +867,11 @@ static ngx_int_t
932
867
ngx_http_gzip_filter_deflate_end (ngx_http_request_t * r ,
933
868
ngx_http_gzip_ctx_t * ctx )
934
869
{
935
- int rc ;
936
- ngx_buf_t * b ;
937
- ngx_chain_t * cl ;
938
- struct gztrailer * trailer ;
870
+ int rc ;
871
+ ngx_chain_t * cl ;
939
872
940
873
ctx -> zin = ctx -> zstream .total_in ;
941
- ctx -> zout = 10 + ctx -> zstream .total_out + 8 ;
874
+ ctx -> zout = ctx -> zstream .total_out ;
942
875
943
876
rc = deflateEnd (& ctx -> zstream );
944
877
@@ -960,50 +893,7 @@ ngx_http_gzip_filter_deflate_end(ngx_http_request_t *r,
960
893
* ctx -> last_out = cl ;
961
894
ctx -> last_out = & cl -> next ;
962
895
963
- if (ctx -> zstream .avail_out >= 8 ) {
964
- trailer = (struct gztrailer * ) ctx -> out_buf -> last ;
965
- ctx -> out_buf -> last += 8 ;
966
- ctx -> out_buf -> last_buf = 1 ;
967
-
968
- } else {
969
- b = ngx_create_temp_buf (r -> pool , 8 );
970
- if (b == NULL ) {
971
- return NGX_ERROR ;
972
- }
973
-
974
- b -> last_buf = 1 ;
975
-
976
- cl = ngx_alloc_chain_link (r -> pool );
977
- if (cl == NULL ) {
978
- return NGX_ERROR ;
979
- }
980
-
981
- cl -> buf = b ;
982
- cl -> next = NULL ;
983
- * ctx -> last_out = cl ;
984
- ctx -> last_out = & cl -> next ;
985
- trailer = (struct gztrailer * ) b -> pos ;
986
- b -> last += 8 ;
987
- }
988
-
989
- #if (NGX_HAVE_LITTLE_ENDIAN && NGX_HAVE_NONALIGNED )
990
-
991
- trailer -> crc32 = ctx -> crc32 ;
992
- trailer -> zlen = ctx -> zin ;
993
-
994
- #else
995
-
996
- trailer -> crc32 [0 ] = (u_char ) (ctx -> crc32 & 0xff );
997
- trailer -> crc32 [1 ] = (u_char ) ((ctx -> crc32 >> 8 ) & 0xff );
998
- trailer -> crc32 [2 ] = (u_char ) ((ctx -> crc32 >> 16 ) & 0xff );
999
- trailer -> crc32 [3 ] = (u_char ) ((ctx -> crc32 >> 24 ) & 0xff );
1000
-
1001
- trailer -> zlen [0 ] = (u_char ) (ctx -> zin & 0xff );
1002
- trailer -> zlen [1 ] = (u_char ) ((ctx -> zin >> 8 ) & 0xff );
1003
- trailer -> zlen [2 ] = (u_char ) ((ctx -> zin >> 16 ) & 0xff );
1004
- trailer -> zlen [3 ] = (u_char ) ((ctx -> zin >> 24 ) & 0xff );
1005
-
1006
- #endif
896
+ ctx -> out_buf -> last_buf = 1 ;
1007
897
1008
898
ctx -> zstream .avail_in = 0 ;
1009
899
ctx -> zstream .avail_out = 0 ;
0 commit comments