0
|
1
|
|
2 /*
|
|
3 * Copyright (C) Igor Sysoev
|
|
4 */
|
|
5
|
|
6
|
|
7 #include <ngx_config.h>
|
|
8 #include <ngx_core.h>
|
|
9 #include <ngx_http.h>
|
|
10
|
|
11
|
|
12
|
|
13 static ngx_int_t ngx_http_not_modified_filter_init(ngx_cycle_t *cycle);
|
|
14
|
|
15
|
|
16 static ngx_http_module_t ngx_http_not_modified_filter_module_ctx = {
|
58
|
17 NULL, /* preconfiguration */
|
|
18 NULL, /* postconfiguration */
|
0
|
19
|
|
20 NULL, /* create main configuration */
|
|
21 NULL, /* init main configuration */
|
|
22
|
|
23 NULL, /* create server configuration */
|
|
24 NULL, /* merge server configuration */
|
|
25
|
|
26 NULL, /* create location configuration */
|
|
27 NULL /* merge location configuration */
|
|
28 };
|
|
29
|
|
30
|
|
31 ngx_module_t ngx_http_not_modified_filter_module = {
|
58
|
32 NGX_MODULE_V1,
|
0
|
33 &ngx_http_not_modified_filter_module_ctx, /* module context */
|
|
34 NULL, /* module directives */
|
|
35 NGX_HTTP_MODULE, /* module type */
|
|
36 ngx_http_not_modified_filter_init, /* init module */
|
10
|
37 NULL /* init process */
|
0
|
38 };
|
|
39
|
|
40
|
|
41 static ngx_http_output_header_filter_pt ngx_http_next_header_filter;
|
|
42
|
|
43
|
|
44 static ngx_int_t ngx_http_not_modified_header_filter(ngx_http_request_t *r)
|
|
45 {
|
|
46 time_t ims;
|
|
47
|
|
48 if (r->headers_out.status != NGX_HTTP_OK
|
58
|
49 || r->main
|
0
|
50 || r->headers_in.if_modified_since == NULL
|
|
51 || r->headers_out.last_modified_time == -1)
|
|
52 {
|
|
53 return ngx_http_next_header_filter(r);
|
|
54 }
|
|
55
|
|
56 ims = ngx_http_parse_time(r->headers_in.if_modified_since->value.data,
|
|
57 r->headers_in.if_modified_since->value.len);
|
|
58
|
|
59 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
60 "http ims:%d lm:%d", ims, r->headers_out.last_modified_time);
|
|
61
|
|
62 /*
|
|
63 * I think that the equality of the dates is correcter
|
|
64 */
|
|
65
|
|
66 if (ims != NGX_ERROR && ims == r->headers_out.last_modified_time) {
|
|
67 r->headers_out.status = NGX_HTTP_NOT_MODIFIED;
|
58
|
68 r->headers_out.content_type.len = 0;
|
0
|
69 r->headers_out.content_length_n = -1;
|
|
70 r->headers_out.content_length = NULL;
|
|
71 #if 0
|
58
|
72 r->headers_out.accept_ranges->hash = 0;
|
0
|
73 #endif
|
|
74 }
|
|
75
|
|
76 return ngx_http_next_header_filter(r);
|
|
77 }
|
|
78
|
|
79
|
|
80 static ngx_int_t ngx_http_not_modified_filter_init(ngx_cycle_t *cycle)
|
|
81 {
|
|
82 ngx_http_next_header_filter = ngx_http_top_header_filter;
|
|
83 ngx_http_top_header_filter = ngx_http_not_modified_header_filter;
|
|
84
|
|
85 return NGX_OK;
|
|
86 }
|