nginx gzip filter模块分析

API:http://refspecs.linuxbase.org/LSB_3.1.1/LSB-Core-generic/LSB-Core-generic/zlib-deflateinit2.html

ngx_http_gzip_header_filter 

1.首先配置信息的验证,是否需要进行gzip压缩

2.给每个请求设置ctx 

3.ctx同时反向关联request

4.ngx_http_gzip_filter_memory 设置wbits,memlevel参数 gzip库调用需要,设置需要分配的内存大小 allocated

5.增加gzip头

6.删除了content_length_n 因为不知道后续的压缩大小为多少.

 

ngx_http_gzip_body_filter 

1.获取header设置的ctx ngx_http_gzip_filter_buffer 复制到新的缓冲 ctx的.

2.调用 ngx_http_gzip_filter_deflate_start,给preallocated 分配空间大小ctx->allocated=header计算的值.

         ctx->free_mem = preallocated ;zstream 设置属性值; 估计是给gzip 设置空间,zstream设置内存对象,内存分配和回收函数

3.调用ngx_chain_add_copy;in的buf导入ctx->in

4.ngx_http_gzip_filter_add_data;ctx->in_buf = ctx->in;ctx->in=ctx->in->next;设置zstream.next_in,zstream_avail_in 通过ctx->in_buf;判断是否为最后一个buf,如果是 ctx->flush;

5.ngx_http_gzip_filter_get_buf;创建临时buf size=conf->bufs.size 设置ctx->zstream.nextout的大小.开始位置到结束位置

6.ngx_http_gzip_filter_deflate ;deflate();

7.ngx_http_gzip_filter_add_data;

8. ngx_http_next_body_filter(r, ctx->out);重新定向了输出流.没有用filter中传入的in

 

转载于:https://www.cnblogs.com/tianc/p/4227845.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值