Skip to content

Commit

Permalink
now we always set Content-Length for the cached responses. thanks And…
Browse files Browse the repository at this point in the history
…re Pascha.
  • Loading branch information
agentzh committed Feb 7, 2011
1 parent dc645d5 commit 2a5858b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
34 changes: 25 additions & 9 deletions src/ngx_http_srcache_filter_module.c
Expand Up @@ -551,6 +551,7 @@ ngx_http_srcache_access_handler(ngx_http_request_t *r)
ngx_http_srcache_main_conf_t *smcf;
ngx_http_srcache_ctx_t *ctx;
ngx_chain_t *cl;
size_t len;

if (r != r->main) {
return NGX_DECLINED;
Expand Down Expand Up @@ -601,29 +602,44 @@ ngx_http_srcache_access_handler(ngx_http_request_t *r)

dd("sending header");

rc = ngx_http_next_header_filter(r);

if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
return rc;
}

dd("sent header from cache: %d", (int) rc);

if (ctx->body_from_cache) {
len = 0;

for (cl = ctx->body_from_cache; cl->next; cl = cl->next) {
/* do nothing */
len += ngx_buf_size(cl->buf);
}

len += ngx_buf_size(cl->buf);

cl->buf->last_buf = 1;

r->headers_out.content_length_n = len;

rc = ngx_http_next_header_filter(r);

if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
return rc;
}

rc = ngx_http_next_body_filter(r, ctx->body_from_cache);

if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
return rc;
}

dd("sent body from cache: %d", (int) rc);

} else {
r->headers_out.content_length_n = 0;

rc = ngx_http_next_header_filter(r);

if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
return rc;
}

dd("sent header from cache: %d", (int) rc);

dd("send last buf for the main request");

cl = ngx_alloc_chain_link(r->pool);
Expand Down
1 change: 1 addition & 0 deletions t/err-page.t
Expand Up @@ -55,6 +55,7 @@ GET /flush
GET /foo
--- response_body
err
--- LAST
Expand Down
6 changes: 5 additions & 1 deletion t/main-req.t
Expand Up @@ -5,7 +5,7 @@ use Test::Nginx::Socket;

#repeat_each(2);

plan tests => repeat_each() * 3 * blocks();
plan tests => repeat_each() * 4 * blocks();

$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;

Expand All @@ -23,6 +23,7 @@ __DATA__
}
--- response_headers
Content-Type: text/plain
Content-Length: 4
--- request
GET /flush
--- response_body eval: "OK\r\n"
Expand Down Expand Up @@ -50,6 +51,7 @@ GET /flush
GET /foo
--- response_headers
Content-Type: text/css
Content-Length:
--- response_body
hello
Expand All @@ -76,6 +78,7 @@ hello
GET /foo
--- response_headers
Content-Type: text/css
Content-Length: 6
--- response_body
hello
Expand Down Expand Up @@ -104,6 +107,7 @@ hello
GET /foo
--- response_headers
Content-Type: text/css
Content-Length: 6
--- response_body
hello

0 comments on commit 2a5858b

Please sign in to comment.