Mercurial > hg > nginx-vendor-0-6
comparison src/http/modules/ngx_http_not_modified_filter.c @ 0:f0b350454894 NGINX_0_1_0
nginx 0.1.0
*) The first public version.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Mon, 04 Oct 2004 00:00:00 +0400 |
parents | |
children | 46833bd150cb |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0b350454894 |
---|---|
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 = { | |
17 NULL, /* pre conf */ | |
18 | |
19 NULL, /* create main configuration */ | |
20 NULL, /* init main configuration */ | |
21 | |
22 NULL, /* create server configuration */ | |
23 NULL, /* merge server configuration */ | |
24 | |
25 NULL, /* create location configuration */ | |
26 NULL /* merge location configuration */ | |
27 }; | |
28 | |
29 | |
30 ngx_module_t ngx_http_not_modified_filter_module = { | |
31 NGX_MODULE, | |
32 &ngx_http_not_modified_filter_module_ctx, /* module context */ | |
33 NULL, /* module directives */ | |
34 NGX_HTTP_MODULE, /* module type */ | |
35 ngx_http_not_modified_filter_init, /* init module */ | |
36 NULL /* init child */ | |
37 }; | |
38 | |
39 | |
40 static ngx_http_output_header_filter_pt ngx_http_next_header_filter; | |
41 | |
42 | |
43 static ngx_int_t ngx_http_not_modified_header_filter(ngx_http_request_t *r) | |
44 { | |
45 time_t ims; | |
46 | |
47 if (r->headers_out.status != NGX_HTTP_OK | |
48 || r->headers_in.if_modified_since == NULL | |
49 || r->headers_out.last_modified_time == -1) | |
50 { | |
51 return ngx_http_next_header_filter(r); | |
52 } | |
53 | |
54 ims = ngx_http_parse_time(r->headers_in.if_modified_since->value.data, | |
55 r->headers_in.if_modified_since->value.len); | |
56 | |
57 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
58 "http ims:%d lm:%d", ims, r->headers_out.last_modified_time); | |
59 | |
60 /* | |
61 * I think that the equality of the dates is correcter | |
62 */ | |
63 | |
64 if (ims != NGX_ERROR && ims == r->headers_out.last_modified_time) { | |
65 r->headers_out.status = NGX_HTTP_NOT_MODIFIED; | |
66 r->headers_out.content_type->key.len = 0; | |
67 r->headers_out.content_type = NULL; | |
68 r->headers_out.content_length_n = -1; | |
69 r->headers_out.content_length = NULL; | |
70 #if 0 | |
71 r->headers_out.accept_ranges->key.len = 0; | |
72 #endif | |
73 } | |
74 | |
75 return ngx_http_next_header_filter(r); | |
76 } | |
77 | |
78 | |
79 static ngx_int_t ngx_http_not_modified_filter_init(ngx_cycle_t *cycle) | |
80 { | |
81 ngx_http_next_header_filter = ngx_http_top_header_filter; | |
82 ngx_http_top_header_filter = ngx_http_not_modified_header_filter; | |
83 | |
84 return NGX_OK; | |
85 } |