Mercurial > hg > nginx-quic
comparison src/http/modules/ngx_http_not_modified_filter.c @ 135:e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sun, 28 Sep 2003 19:29:06 +0000 |
parents | |
children | da00cde00e8a |
comparison
equal
deleted
inserted
replaced
134:d57c6835225c | 135:e29909bd9b8a |
---|---|
1 | |
2 #include <ngx_config.h> | |
3 #include <ngx_core.h> | |
4 #include <ngx_http.h> | |
5 | |
6 | |
7 | |
8 static int ngx_http_not_modified_filter_init(ngx_cycle_t *cycle); | |
9 | |
10 | |
11 static ngx_http_module_t ngx_http_not_modified_filter_module_ctx = { | |
12 NULL, /* create main configuration */ | |
13 NULL, /* init main configuration */ | |
14 | |
15 NULL, /* create server configuration */ | |
16 NULL, /* merge server configuration */ | |
17 | |
18 NULL, /* create location configuration */ | |
19 NULL /* merge location configuration */ | |
20 }; | |
21 | |
22 | |
23 ngx_module_t ngx_http_not_modified_filter_module = { | |
24 NGX_MODULE, | |
25 &ngx_http_not_modified_filter_module_ctx, /* module context */ | |
26 NULL, /* module directives */ | |
27 NGX_HTTP_MODULE, /* module type */ | |
28 ngx_http_not_modified_filter_init, /* init module */ | |
29 NULL /* init child */ | |
30 }; | |
31 | |
32 | |
33 static int (*next_header_filter) (ngx_http_request_t *r); | |
34 | |
35 | |
36 static int ngx_http_not_modified_header_filter(ngx_http_request_t *r) | |
37 { | |
38 time_t ims; | |
39 | |
40 if (r->headers_out.status != NGX_HTTP_OK | |
41 || r->headers_in.if_modified_since == NULL | |
42 || r->headers_out.last_modified_time == NULL) | |
43 { | |
44 return next_header_filter(r); | |
45 } | |
46 | |
47 ims = ngx_http_parse_time(r->headers_in.if_modified_since->value.data, | |
48 r->headers_in.if_modified_since->value.len); | |
49 | |
50 ngx_log_debug(r->connection->log, "%d %d" _ | |
51 ims _ r->headers_out.last_modified_time); | |
52 | |
53 /* I think that the date equality is correcter */ | |
54 | |
55 if (ims != NGX_ERROR && ims == r->headers_out.last_modified_time) { | |
56 r->headers_out.status = NGX_HTTP_NOT_MODIFIED; | |
57 r->headers_out.content_length = -1; | |
58 r->headers_out.content_type->key.len = 0; | |
59 r->headers_out.content_type = NULL; | |
60 | |
61 /* TODO: delete "Accept-Ranges" header | |
62 } | |
63 | |
64 return next_header_filter(r); | |
65 } | |
66 | |
67 | |
68 static int ngx_http_not_modified_filter_init(ngx_cycle_t *cycle) | |
69 { | |
70 next_header_filter = ngx_http_top_header_filter; | |
71 ngx_http_top_header_filter = ngx_http_not_modified_header_filter; | |
72 | |
73 return NGX_OK; | |
74 } |