Nginx gzip filter module analysis, nginxgzip

Source: Internet
Author: User

Nginx gzip filter module analysis, nginxgzip

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

Ngx_http_gzip_header_filter

1. Check whether gzip compression is required for configuration information verification.

2. Set ctx for each request

3. ctx reverse Association request

4. ngx_http_gzip_filter_memory: Set wbits. For calling the gzip library with the memlevel parameter, set the memory size to be allocated to allocated.

5. Add a gzip Header

6. The content_length_n is deleted because it does not know the subsequent compression size.

 

Ngx_http_gzip_body_filter

1. Obtain the ctx ngx_http_gzip_filter_buffer set in the header and copy it to the new ctx buffer.

2. Call ngx_http_gzip_filter_deflate_start to allocate space for preallocated ctx-> allocated = header.

Ctx-> free_mem = preallocated; zstream sets the attribute value. It is estimated that it sets space for gzip, zstream sets memory objects, and memory allocation and recovery functions.

3. Call the ngx_chain_add_copy; in buf to import ctx-> in

4. ngx_http_gzip_filter_add_data; ctx-> in_buf = ctx-> in; ctx-> in = ctx-> in-> next; Set zstream. next_in, zstream_avail_in uses ctx-> in_buf; to determine whether it is the last buf. If it is ctx-> flush;

5. ngx_http_gzip_filter_get_buf; create a temporary buf size = conf-> bufs. size and set the size of ctx-> zstream. nextout. the start position is the end position.

6. ngx_http_gzip_filter_deflate; deflate ();

7. ngx_http_gzip_filter_add_data;

8. ngx_http_next_body_filter (r, ctx-> out); the output stream is redirected again.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.