From 0e0493232b5e353f59e616f7ce30b2fbed9b2b7a Mon Sep 17 00:00:00 2001 From: Sebastien Chauvin Date: Mon, 1 Jul 2024 13:14:48 +0200 Subject: [PATCH] feat: propagate upstream http code and log upstream URI in case of error --- ngx_child_http_request.c | 13 ++++++++++++- ngx_child_http_request.h | 4 ++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ngx_child_http_request.c b/ngx_child_http_request.c index c50acd30..6dfbabb5 100644 --- a/ngx_child_http_request.c +++ b/ngx_child_http_request.c @@ -188,11 +188,22 @@ ngx_child_request_wev_handler(ngx_http_request_t *r) b->last = b->pos; break; + case NGX_HTTP_BAD_REQUEST: + case NGX_HTTP_NOT_FOUND: + case NGX_HTTP_FORBIDDEN: + case NGX_HTTP_GONE: + ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, + "ngx_child_request_wev_handler: upstream: %s, uri: %s, status: %ui", + u->schema.data, sr->uri.data, u->headers_in.status_n); + rc = u->headers_in.status_n; + break; + default: if (u->headers_in.status_n != 0) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "ngx_child_request_wev_handler: upstream returned a bad status %ui", u->headers_in.status_n); + "ngx_child_request_wev_handler: upstream: %s, uri: %s, status: %ui", + u->schema.data, sr->uri.data, u->headers_in.status_n); } else { diff --git a/ngx_child_http_request.h b/ngx_child_http_request.h index 10d0f328..c5179271 100644 --- a/ngx_child_http_request.h +++ b/ngx_child_http_request.h @@ -4,6 +4,10 @@ // includes #include +#ifndef NGX_HTTP_GONE +#define NGX_HTTP_GONE 410 +#endif + // typedefs typedef void(*ngx_child_request_callback_t)(void* context, ngx_int_t rc, ngx_buf_t* buf, ssize_t bytes_read);