Analyze the function of Nginx filter module

Source: Internet
Author: User
Keywords Nginx Filter module
Tags analysis basic client example function modified nginx set

4.1. Analyze Head Filter function

The head filter function consists of the following three base sections:

1. Decide whether to manipulate this reply

2. Manipulate this response

3. Call the next filter function

For example, here is a simple version of the "unmodified" header filter function. If the client's if-modfied-since head matches the last-modified header of the reply, the State is set to 304 not flushes. The head filter function has only one parameter ngx_http_request_t, but it allows us to access the client's head and shortly to send the reply head.

Static

ngx_int_t Ngx_http_not_modified_header_filter (ngx_http_request_t *r) {

time_t if_modified_since;

If_modified_since = Ngx_http_parse_time (R->headers_in.if_modified_since->value.data, r->headers_in.if_ Modified_since->value.len);

/* Step 1:decide whether to operate * *

if (if_modified_since!= ngx_error && if_modified_since = = r->headers_out.last_modified_time) {

/* Step 2:operate on the header * *

R->headers_out.status = ngx_http_not_modified;

R->headers_out.content_type.len = 0;

Ngx_http_clear_content_length (R);

Ngx_http_clear_accept_ranges (R);

}

/* Step 3:call the next filter * *

return Ngx_http_next_header_filter (R);

}

The headers_out structure is the same as in the processing module (http/ngx_http_request.h) and can be changed arbitrarily.

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.