Skip to content

Commit f5e860f

Browse files
committed
bugfix: HEAD and conditional GET requests would still fall back to content handler execution (leading to backend accesses) even in case of a cache hit. thanks Wang Lichao for reporting this issue.
1 parent efbbdd0 commit f5e860f

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

src/ngx_http_srcache_fetch.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,16 @@ ngx_http_srcache_access_handler(ngx_http_request_t *r)
154154

155155
dd("srcache fetch header returned %d", (int) rc);
156156

157-
if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
157+
if (rc == NGX_ERROR || rc > NGX_OK) {
158158
return rc;
159159
}
160160

161+
#if 1
162+
if (r->header_only) {
163+
return NGX_HTTP_OK;
164+
}
165+
#endif
166+
161167
if (!r->filter_finalize) {
162168
rc = ngx_http_srcache_next_body_filter(r,
163169
ctx->body_from_cache);

t/conditional-get.t

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ hello
7676
7777
default_type text/css;
7878
79-
echo world;
79+
proxy_pass http://agentzh.org:12345/;
8080
}
8181
8282
location /memc {
@@ -107,7 +107,7 @@ hello
107107
108108
default_type text/css;
109109
110-
echo world;
110+
proxy_pass http://agentzh.org:12345/;
111111
}
112112
113113
location /memc {
@@ -125,6 +125,11 @@ If-Modified-Since: Thu, 10 May 2012 07:50:59 GMT
125125
!Content-Type
126126
!Content-Length
127127
Last-Modified: Thu, 10 May 2012 07:50:59 GMT
128+
--- stap2
129+
F(ngx_http_core_content_phase) {
130+
printf("r content handler: %s\n", usymname($r->content_handler))
131+
}
132+
128133
--- error_code: 304
129134
--- response_body
130135
--- no_error_log
@@ -140,7 +145,7 @@ Last-Modified: Thu, 10 May 2012 07:50:59 GMT
140145
141146
default_type text/css;
142147
143-
echo world;
148+
proxy_pass http://agentzh.org:12345/;
144149
}
145150
146151
location /memc {
@@ -174,7 +179,7 @@ hello
174179
175180
default_type text/css;
176181
177-
echo world;
182+
proxy_pass http://agentzh.org:12345/;
178183
}
179184
180185
location /memc {
@@ -208,7 +213,7 @@ Last-Modified: Thu, 10 May 2012 07:50:59 GMT
208213
209214
default_type text/css;
210215
211-
echo world;
216+
proxy_pass http://agentzh.org:12345/;
212217
}
213218
214219
location /memc {
@@ -241,7 +246,7 @@ Content-Length: 182
241246
242247
default_type text/css;
243248
244-
echo world;
249+
proxy_pass http://agentzh.org:12345/;
245250
}
246251
247252
location /memc {
@@ -274,7 +279,7 @@ hello
274279
275280
default_type text/css;
276281
277-
echo world;
282+
proxy_pass http://agentzh.org:12345/;
278283
}
279284
280285
location /memc {

t/methods.t

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ hello
6565
srcache_fetch GET /memc $uri;
6666
srcache_store PUT /memc $uri;
6767
68-
echo world;
68+
proxy_pass http://agentzh.org:12345/;
6969
}
7070
7171
location /memc {
@@ -121,7 +121,7 @@ world
121121
srcache_store PUT /memc $uri;
122122
srcache_methods POST;
123123
124-
echo world;
124+
proxy_pass http://agentzh.org:12345/;
125125
}
126126
127127
location /memc {
@@ -150,7 +150,7 @@ hello
150150
srcache_store PUT /memc $uri;
151151
srcache_methods POST PUT;
152152
153-
echo world;
153+
proxy_pass http://agentzh.org:12345/;
154154
}
155155
156156
location /memc {
@@ -178,7 +178,7 @@ hello
178178
srcache_store PUT /memc $uri;
179179
srcache_methods POST;
180180
181-
echo world;
181+
proxy_pass http://agentzh.org:12345/;
182182
}
183183
184184
location /memc {
@@ -320,7 +320,7 @@ hello
320320
srcache_fetch GET /memc $uri;
321321
srcache_store PUT /memc $uri;
322322
323-
echo world;
323+
proxy_pass http://agentzh.org:12345/;
324324
}
325325
326326
location /memc {

0 commit comments

Comments
 (0)