~nginx/nginx/1.0

« back to all changes in this revision

Viewing changes to src/http/modules/ngx_http_not_modified_filter_module.c

  • Committer: Michael Lustfield
  • Date: 2010-12-08 05:46:19 UTC
  • Revision ID: michael@profarius.com-20101208054619-q0l7ak00atomn5z4
Tags: 0.9.2
VersionĀ 0.9.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
#include <ngx_http.h>
10
10
 
11
11
 
12
 
 
 
12
static ngx_int_t ngx_http_test_precondition(ngx_http_request_t *r);
 
13
static ngx_int_t ngx_http_test_not_modified(ngx_http_request_t *r);
13
14
static ngx_int_t ngx_http_not_modified_filter_init(ngx_conf_t *cf);
14
15
 
15
16
 
50
51
static ngx_int_t
51
52
ngx_http_not_modified_header_filter(ngx_http_request_t *r)
52
53
{
53
 
    time_t                     ims;
54
 
    ngx_http_core_loc_conf_t  *clcf;
55
 
 
56
54
    if (r->headers_out.status != NGX_HTTP_OK
57
55
        || r != r->main
58
 
        || r->headers_in.if_modified_since == NULL
59
56
        || r->headers_out.last_modified_time == -1)
60
57
    {
61
58
        return ngx_http_next_header_filter(r);
62
59
    }
 
60
 
 
61
    if (r->headers_in.if_unmodified_since) {
 
62
        return ngx_http_test_precondition(r);
 
63
    }
 
64
 
 
65
    if (r->headers_in.if_modified_since) {
 
66
        return ngx_http_test_not_modified(r);
 
67
    }
 
68
 
 
69
    return ngx_http_next_header_filter(r);
 
70
}
 
71
 
 
72
 
 
73
static ngx_int_t
 
74
ngx_http_test_precondition(ngx_http_request_t *r)
 
75
{
 
76
    time_t  iums;
 
77
 
 
78
    iums = ngx_http_parse_time(r->headers_in.if_unmodified_since->value.data,
 
79
                               r->headers_in.if_unmodified_since->value.len);
 
80
 
 
81
    ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
 
82
                 "http iums:%d lm:%d", iums, r->headers_out.last_modified_time);
 
83
 
 
84
    if (iums >= r->headers_out.last_modified_time) {
 
85
        return ngx_http_next_header_filter(r);
 
86
    }
 
87
 
 
88
    return ngx_http_filter_finalize_request(r, NULL,
 
89
                                            NGX_HTTP_PRECONDITION_FAILED);
 
90
}
 
91
 
 
92
 
 
93
static ngx_int_t
 
94
ngx_http_test_not_modified(ngx_http_request_t *r)
 
95
{
 
96
    time_t                     ims;
 
97
    ngx_http_core_loc_conf_t  *clcf;
63
98
 
64
99
    clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
65
100