Welcome! Log In Create A New Profile

Advanced

[PATCH 2 of 3] Upstream: allow recovery from "429 Too Many Requests" response

Piotr Sikora via nginx-devel
February 28, 2017 06:42PM
# HG changeset patch
# User Piotr Sikora <piotrsikora@google.com>
# Date 1488324535 28800
# Tue Feb 28 15:28:55 2017 -0800
# Node ID e21f12a958010e1f3e5cdc1640859e335e032ca5
# Parent 9a63d6e990d230db0ec6b03250265447f648526e
Upstream: allow recovery from "429 Too Many Requests" response.

This change adds "http_429" parameter to "proxy_next_upstream" for
retrying rate-limited requests, and to "proxy_cache_use_stale" for
serving stale cached responses after being rate-limited.

Signed-off-by: Piotr Sikora <piotrsikora@google.com>

diff -r 9a63d6e990d2 -r e21f12a95801 src/http/modules/ngx_http_fastcgi_module.c
--- a/src/http/modules/ngx_http_fastcgi_module.c
+++ b/src/http/modules/ngx_http_fastcgi_module.c
@@ -211,6 +211,7 @@ static ngx_conf_bitmask_t ngx_http_fast
{ ngx_string("http_503"), NGX_HTTP_UPSTREAM_FT_HTTP_503 },
{ ngx_string("http_403"), NGX_HTTP_UPSTREAM_FT_HTTP_403 },
{ ngx_string("http_404"), NGX_HTTP_UPSTREAM_FT_HTTP_404 },
+ { ngx_string("http_429"), NGX_HTTP_UPSTREAM_FT_HTTP_429 },
{ ngx_string("updating"), NGX_HTTP_UPSTREAM_FT_UPDATING },
{ ngx_string("off"), NGX_HTTP_UPSTREAM_FT_OFF },
{ ngx_null_string, 0 }
diff -r 9a63d6e990d2 -r e21f12a95801 src/http/modules/ngx_http_proxy_module.c
--- a/src/http/modules/ngx_http_proxy_module.c
+++ b/src/http/modules/ngx_http_proxy_module.c
@@ -220,6 +220,7 @@ static ngx_conf_bitmask_t ngx_http_prox
{ ngx_string("http_504"), NGX_HTTP_UPSTREAM_FT_HTTP_504 },
{ ngx_string("http_403"), NGX_HTTP_UPSTREAM_FT_HTTP_403 },
{ ngx_string("http_404"), NGX_HTTP_UPSTREAM_FT_HTTP_404 },
+ { ngx_string("http_429"), NGX_HTTP_UPSTREAM_FT_HTTP_429 },
{ ngx_string("updating"), NGX_HTTP_UPSTREAM_FT_UPDATING },
{ ngx_string("off"), NGX_HTTP_UPSTREAM_FT_OFF },
{ ngx_null_string, 0 }
diff -r 9a63d6e990d2 -r e21f12a95801 src/http/modules/ngx_http_scgi_module.c
--- a/src/http/modules/ngx_http_scgi_module.c
+++ b/src/http/modules/ngx_http_scgi_module.c
@@ -82,6 +82,7 @@ static ngx_conf_bitmask_t ngx_http_scgi_
{ ngx_string("http_503"), NGX_HTTP_UPSTREAM_FT_HTTP_503 },
{ ngx_string("http_403"), NGX_HTTP_UPSTREAM_FT_HTTP_403 },
{ ngx_string("http_404"), NGX_HTTP_UPSTREAM_FT_HTTP_404 },
+ { ngx_string("http_429"), NGX_HTTP_UPSTREAM_FT_HTTP_429 },
{ ngx_string("updating"), NGX_HTTP_UPSTREAM_FT_UPDATING },
{ ngx_string("off"), NGX_HTTP_UPSTREAM_FT_OFF },
{ ngx_null_string, 0 }
diff -r 9a63d6e990d2 -r e21f12a95801 src/http/modules/ngx_http_uwsgi_module.c
--- a/src/http/modules/ngx_http_uwsgi_module.c
+++ b/src/http/modules/ngx_http_uwsgi_module.c
@@ -114,6 +114,7 @@ static ngx_conf_bitmask_t ngx_http_uwsgi
{ ngx_string("http_503"), NGX_HTTP_UPSTREAM_FT_HTTP_503 },
{ ngx_string("http_403"), NGX_HTTP_UPSTREAM_FT_HTTP_403 },
{ ngx_string("http_404"), NGX_HTTP_UPSTREAM_FT_HTTP_404 },
+ { ngx_string("http_429"), NGX_HTTP_UPSTREAM_FT_HTTP_429 },
{ ngx_string("updating"), NGX_HTTP_UPSTREAM_FT_UPDATING },
{ ngx_string("off"), NGX_HTTP_UPSTREAM_FT_OFF },
{ ngx_null_string, 0 }
diff -r 9a63d6e990d2 -r e21f12a95801 src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -436,6 +436,7 @@ static ngx_http_upstream_next_t ngx_htt
{ 504, NGX_HTTP_UPSTREAM_FT_HTTP_504 },
{ 403, NGX_HTTP_UPSTREAM_FT_HTTP_403 },
{ 404, NGX_HTTP_UPSTREAM_FT_HTTP_404 },
+ { 429, NGX_HTTP_UPSTREAM_FT_HTTP_429 },
{ 0, 0 }
};

@@ -4115,7 +4116,8 @@ ngx_http_upstream_next(ngx_http_request_
if (u->peer.sockaddr) {

if (ft_type == NGX_HTTP_UPSTREAM_FT_HTTP_403
- || ft_type == NGX_HTTP_UPSTREAM_FT_HTTP_404)
+ || ft_type == NGX_HTTP_UPSTREAM_FT_HTTP_404
+ || ft_type == NGX_HTTP_UPSTREAM_FT_HTTP_429)
{
state = NGX_PEER_NEXT;

@@ -4155,6 +4157,10 @@ ngx_http_upstream_next(ngx_http_request_
status = NGX_HTTP_NOT_FOUND;
break;

+ case NGX_HTTP_UPSTREAM_FT_HTTP_429:
+ status = NGX_HTTP_TOO_MANY_REQUESTS;
+ break;
+
/*
* NGX_HTTP_UPSTREAM_FT_BUSY_LOCK and NGX_HTTP_UPSTREAM_FT_MAX_WAITING
* never reach here
diff -r 9a63d6e990d2 -r e21f12a95801 src/http/ngx_http_upstream.h
--- a/src/http/ngx_http_upstream.h
+++ b/src/http/ngx_http_upstream.h
@@ -26,10 +26,11 @@
#define NGX_HTTP_UPSTREAM_FT_HTTP_504 0x00000080
#define NGX_HTTP_UPSTREAM_FT_HTTP_403 0x00000100
#define NGX_HTTP_UPSTREAM_FT_HTTP_404 0x00000200
-#define NGX_HTTP_UPSTREAM_FT_UPDATING 0x00000400
-#define NGX_HTTP_UPSTREAM_FT_BUSY_LOCK 0x00000800
-#define NGX_HTTP_UPSTREAM_FT_MAX_WAITING 0x00001000
-#define NGX_HTTP_UPSTREAM_FT_NON_IDEMPOTENT 0x00002000
+#define NGX_HTTP_UPSTREAM_FT_HTTP_429 0x00000400
+#define NGX_HTTP_UPSTREAM_FT_UPDATING 0x00000800
+#define NGX_HTTP_UPSTREAM_FT_BUSY_LOCK 0x00001000
+#define NGX_HTTP_UPSTREAM_FT_MAX_WAITING 0x00002000
+#define NGX_HTTP_UPSTREAM_FT_NON_IDEMPOTENT 0x00004000
#define NGX_HTTP_UPSTREAM_FT_NOLIVE 0x40000000
#define NGX_HTTP_UPSTREAM_FT_OFF 0x80000000

@@ -38,7 +39,8 @@
|NGX_HTTP_UPSTREAM_FT_HTTP_503 \
|NGX_HTTP_UPSTREAM_FT_HTTP_504 \
|NGX_HTTP_UPSTREAM_FT_HTTP_403 \
- |NGX_HTTP_UPSTREAM_FT_HTTP_404)
+ |NGX_HTTP_UPSTREAM_FT_HTTP_404 \
+ |NGX_HTTP_UPSTREAM_FT_HTTP_429)

#define NGX_HTTP_UPSTREAM_INVALID_HEADER 40

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

[PATCH 1 of 2] HTTP: add support for "429 Too Many Requests" response (RFC6585)

Piotr Sikora 990 October 19, 2016 03:54AM

[PATCH 2 of 2] HTTP: change default response code when rate-limiting requests

Piotr Sikora 303 October 19, 2016 03:54AM

Re: [PATCH 1 of 2] HTTP: add support for "429 Too Many Requests" response (RFC6585)

Piotr Sikora via nginx-devel 287 November 29, 2016 08:10PM

Re: [PATCH 1 of 2] HTTP: add support for "429 Too Many Requests" response (RFC6585)

Piotr Sikora via nginx-devel 381 January 20, 2017 08:04PM

Re: [PATCH 1 of 2] HTTP: add support for "429 Too Many Requests" response (RFC6585)

Piotr Sikora via nginx-devel 231 February 22, 2017 10:40PM

Re: [PATCH 1 of 2] HTTP: add support for "429 Too Many Requests" response (RFC6585)

Maxim Dounin 237 February 25, 2017 06:46PM

[PATCH 1 of 3] HTTP: add support for "429 Too Many Requests" response (RFC6585)

Piotr Sikora via nginx-devel 586 February 28, 2017 06:42PM

[PATCH 2 of 3] Upstream: allow recovery from "429 Too Many Requests" response

Piotr Sikora via nginx-devel 287 February 28, 2017 06:42PM

Re: [PATCH 2 of 3] Upstream: allow recovery from "429 Too Many Requests" response

Maxim Dounin 231 March 01, 2017 10:34AM

Re: [PATCH 2 of 3] Upstream: allow recovery from "429 Too Many Requests" response

Piotr Sikora via nginx-devel 226 March 01, 2017 03:18PM

Re: [PATCH 2 of 3] Upstream: allow recovery from "429 Too Many Requests" response

Maxim Dounin 242 March 01, 2017 07:00PM

Re: [PATCH 2 of 3] Upstream: allow recovery from "429 Too Many Requests" response

Piotr Sikora via nginx-devel 239 March 24, 2017 06:50AM

[PATCH 3 of 3] Limit req: change default response code when rate-limiting

Piotr Sikora via nginx-devel 219 February 28, 2017 06:42PM

Re: [PATCH 3 of 3] Limit req: change default response code when rate-limiting

Maxim Dounin 227 March 01, 2017 10:40AM

Re: [PATCH 3 of 3] Limit req: change default response code when rate-limiting

Piotr Sikora via nginx-devel 217 March 01, 2017 03:22PM

Re: [PATCH 3 of 3] Limit req: change default response code when rate-limiting

Maxim Dounin 252 March 01, 2017 07:18PM



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

Online Users

Guests: 243
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready