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.