Welcome! Log In Create A New Profile

Advanced

Proxy_no_cache question

Eloy Coto Pereiro
June 03, 2021 04:14AM
Hi,

I was checking how proxy_no_cache is handled, and I want to open a
discussion
here. When it is set to off, should the ngx_http_upstream_cache[0] call at
all? I
mean, why start the cache options when it's not enabled at all?

The primary use case is when the cache is disabled, and things regarding
cache
are still in there like proxy_cache_convert_head, etc..

I have a small patch about what I'm trying to do. Is it something that you
will
accept at all?

[0]
https://github.com/nginx/nginx/blob/5eadaf69e394c030056e4190d86dae0262f8617c/src/http/ngx_http_upstream.c#L823

Patch(Not complete at all)

diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
index 61fad5ca..1217767d 100644
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -566,42 +566,55 @@ ngx_http_upstream_init_request(ngx_http_request_t *r)
#if (NGX_HTTP_CACHE)

if (u->conf->cache) {
- ngx_int_t rc;

- rc = ngx_http_upstream_cache(r, u);
+ switch (ngx_http_test_predicates(r, u->conf->no_cache)) {

- if (rc == NGX_BUSY) {
- r->write_event_handler = ngx_http_upstream_init_request;
- return;
- }
+ case NGX_ERROR:
+ return;

- r->write_event_handler = ngx_http_request_empty_handler;
+ case NGX_DECLINED:
+ /* No need to configure cache at all */
+ break;
+ default: {/* NGX_OK */
+ ngx_int_t rc;
+ rc = ngx_http_upstream_cache(r, u);

- if (rc == NGX_ERROR) {
- ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
+ if (rc == NGX_BUSY) {
+ r->write_event_handler = ngx_http_upstream_init_request;
+ return;
+ }

- if (rc == NGX_OK) {
- rc = ngx_http_upstream_cache_send(r, u);
+ r->write_event_handler = ngx_http_request_empty_handler;

- if (rc == NGX_DONE) {
- return;
- }
+ if (rc == NGX_ERROR) {
+ ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
+ return;
+ }

- if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) {
- rc = NGX_DECLINED;
- r->cached = 0;
- u->buffer.start = NULL;
- u->cache_status = NGX_HTTP_CACHE_MISS;
- u->request_sent = 1;
- }
- }
+ if (rc == NGX_OK) {
+ rc = ngx_http_upstream_cache_send(r, u);
+
+ if (rc == NGX_DONE) {
+ return;
+ }
+
+ if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) {
+ rc = NGX_DECLINED;
+ r->cached = 0;
+ u->buffer.start = NULL;
+ u->cache_status = NGX_HTTP_CACHE_MISS;
+ u->request_sent = 1;
+ }
+ }
+
+ if (rc != NGX_DECLINED) {
+ ngx_http_finalize_request(r, rc);
+ return;
+ }
+ break;
+ }
+ }

- if (rc != NGX_DECLINED) {
- ngx_http_finalize_request(r, rc);
- return;
- }
}

#endif
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

Proxy_no_cache question

Eloy Coto Pereiro 124 June 03, 2021 04:14AM

Re: Proxy_no_cache question

Maxim Dounin 47 June 03, 2021 09:24AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 83
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready