1 
2 /*
3  * Copyright (C) Yichun Zhang (agentzh)
4  */
5 
6 
7 #ifndef _NGX_HTTP_SRCACHE_FILTER_MODULE_H_INCLUDED_
8 #define _NGX_HTTP_SRCACHE_FILTER_MODULE_H_INCLUDED_
9 
10 
11 #include <ngx_core.h>
12 #include <ngx_http.h>
13 #include <nginx.h>
14 
15 
16 enum {
17     NGX_HTTP_SRCACHE_FETCH_BYPASS = 0,
18     NGX_HTTP_SRCACHE_FETCH_MISS   = 1,
19     NGX_HTTP_SRCACHE_FETCH_HIT    = 2
20 };
21 
22 
23 enum {
24     NGX_HTTP_SRCACHE_STORE_BYPASS = 0,
25     NGX_HTTP_SRCACHE_STORE_STORE  = 1
26 };
27 
28 
29 extern ngx_module_t  ngx_http_srcache_filter_module;
30 
31 
32 typedef struct {
33     ngx_uint_t                  method;
34     ngx_str_t                   method_name;
35     ngx_http_complex_value_t    location;
36     ngx_http_complex_value_t    args;
37 
38 } ngx_http_srcache_request_t;
39 
40 
41 typedef struct {
42     ngx_uint_t                  method;
43     ngx_str_t                   method_name;
44     ngx_str_t                   location;
45     ngx_str_t                   args;
46     ngx_http_request_body_t    *request_body;
47     ssize_t                     content_length_n;
48 
49 } ngx_http_srcache_parsed_request_t;
50 
51 
52 typedef struct {
53     ngx_http_srcache_request_t      *fetch;
54     ngx_http_srcache_request_t      *store;
55     size_t                           buf_size;
56     size_t                           store_max_size;
57     size_t                           header_buf_size;
58 
59     ngx_http_complex_value_t        *fetch_skip;
60     ngx_http_complex_value_t        *store_skip;
61 
62     ngx_uint_t                       cache_methods;
63 
64     ngx_int_t                       *store_statuses;
65 
66     ngx_flag_t                       req_cache_control;
67     ngx_flag_t                       resp_cache_control;
68 
69     ngx_flag_t                       store_private;
70     ngx_flag_t                       store_no_store;
71     ngx_flag_t                       store_no_cache;
72     ngx_flag_t                       store_ranges;
73 
74     ngx_flag_t                       ignore_content_encoding;
75 
76     ngx_hash_t                       hide_headers_hash;
77     ngx_array_t                     *hide_headers;
78     ngx_array_t                     *pass_headers;
79 
80     time_t                           max_expire;
81     time_t                           default_expire;
82 
83     unsigned                         postponed_to_access_phase_end:1;
84     unsigned                         hide_content_type:1;
85     unsigned                         hide_last_modified:1;
86 } ngx_http_srcache_loc_conf_t;
87 
88 
89 typedef struct {
90     unsigned            postponed_to_access_phase_end;
91     unsigned            module_used;
92     ngx_hash_t          headers_in_hash;
93 
94 } ngx_http_srcache_main_conf_t;
95 
96 
97 typedef struct ngx_http_srcache_ctx_s  ngx_http_srcache_ctx_t;
98 
99 typedef struct ngx_http_srcache_postponed_request_s
100     ngx_http_srcache_postponed_request_t;
101 
102 
103 struct ngx_http_srcache_ctx_s {
104     ngx_chain_t                     *body_from_cache;
105     ngx_chain_t                     *body_to_cache;
106     size_t                           response_length;
107     size_t                           response_body_length;
108     void                            *store_wev_handler_ctx;
109 
110     ngx_int_t                      (*process_header)(ngx_http_request_t *r,
111                                                      ngx_buf_t *b);
112 
113     time_t                           valid_sec;
114 
115     ngx_http_status_t                status;
116     ngx_buf_t                       *header_buf;
117 
118     ngx_http_srcache_postponed_request_t  *postponed_requests;
119 
120     ngx_uint_t      http_status; /* the HTTP status code that has been
121                                     actually sent */
122 
123     unsigned        waiting_subrequest:1;
124     unsigned        request_done:1;
125     unsigned        from_cache:1;
126     /* unsigned      fetch_error:1; */
127     unsigned        in_fetch_subrequest:1;
128     unsigned        in_store_subrequest:1;
129     unsigned        ignore_body:1;
130     unsigned        parsing_cached_headers:1;
131     unsigned        store_response:1;
132     unsigned        store_skip:1;
133     unsigned        issued_fetch_subrequest:1;
134     unsigned        seen_subreq_eof:1;
135     unsigned        waiting_request_body:1;
136     unsigned        request_body_done:1;
137 };
138 
139 
140 struct ngx_http_srcache_postponed_request_s {
141     ngx_http_srcache_postponed_request_t     *next;
142 
143     ngx_http_request_t              *request;
144     ngx_http_srcache_ctx_t          *ctx;
145     unsigned                         ready:1;
146     unsigned                         done:1;
147 };
148 
149 
150 #endif  /* _NGX_HTTP_SRCACHE_FILTER_MODULE_H_INCLUDED_ */
151 
152 /* vi:set ft=c ts=4 sw=4 et fdm=marker: */
153