Mercurial > hg > nginx
comparison src/http/ngx_http_upstream.c @ 7116:46ddff109e72
Upstream: better handling of invalid headers in cache files.
If cache file is truncated, it is possible that u->process_header()
will return NGX_AGAIN. Added appropriate handling of this case by
changing the error to NGX_HTTP_UPSTREAM_INVALID_HEADER.
Also, added appropriate logging of this and NGX_HTTP_UPSTREAM_INVALID_HEADER
cases at the "crit" level. Note that this will result in duplicate logging
in case of NGX_HTTP_UPSTREAM_INVALID_HEADER. While this is something better
to avoid, it is considered to be an overkill to implement cache-specific
error logging in u->process_header().
Additionally, u->buffer.start is now reset to be able to receive a new
response, and u->cache_status set to MISS to provide the value in the
$upstream_cache_status variable, much like it happens on other cache file
errors detected by ngx_http_file_cache_read(), instead of HIT, which is
believed to be misleading.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 02 Oct 2017 19:10:20 +0300 |
parents | acc2cddc7b45 |
children | dbd77a638eb7 |
comparison
equal
deleted
inserted
replaced
7115:4ff31c785d0c | 7116:46ddff109e72 |
---|---|
580 } | 580 } |
581 | 581 |
582 if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) { | 582 if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) { |
583 rc = NGX_DECLINED; | 583 rc = NGX_DECLINED; |
584 r->cached = 0; | 584 r->cached = 0; |
585 u->buffer.start = NULL; | |
586 u->cache_status = NGX_HTTP_CACHE_MISS; | |
585 } | 587 } |
586 | 588 |
587 if (ngx_http_upstream_cache_background_update(r, u) != NGX_OK) { | 589 if (ngx_http_upstream_cache_background_update(r, u) != NGX_OK) { |
588 rc = NGX_ERROR; | 590 rc = NGX_ERROR; |
589 } | 591 } |
1057 | 1059 |
1058 if (rc == NGX_ERROR) { | 1060 if (rc == NGX_ERROR) { |
1059 return NGX_ERROR; | 1061 return NGX_ERROR; |
1060 } | 1062 } |
1061 | 1063 |
1064 if (rc == NGX_AGAIN) { | |
1065 rc = NGX_HTTP_UPSTREAM_INVALID_HEADER; | |
1066 } | |
1067 | |
1062 /* rc == NGX_HTTP_UPSTREAM_INVALID_HEADER */ | 1068 /* rc == NGX_HTTP_UPSTREAM_INVALID_HEADER */ |
1069 | |
1070 ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0, | |
1071 "cache file \"%s\" contains invalid header", | |
1072 c->file.name.data); | |
1063 | 1073 |
1064 /* TODO: delete file */ | 1074 /* TODO: delete file */ |
1065 | 1075 |
1066 return rc; | 1076 return rc; |
1067 } | 1077 } |