Skip to content

Commit

Permalink
feat: propagate upstream http code and log upstream URI in case of error
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienChauvin committed Jul 1, 2024
1 parent 92a45b7 commit 0e04932
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
13 changes: 12 additions & 1 deletion ngx_child_http_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
4 changes: 4 additions & 0 deletions ngx_child_http_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
// includes
#include <ngx_http.h>

#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);

Expand Down

0 comments on commit 0e04932

Please sign in to comment.