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.