Skip to content

Commit 5f546dd

Browse files
committed
fix(proxies): save backend status code before update, use it for action filtering, update agent to always use status code from rule for action filtering
1 parent f8ac689 commit 5f546dd

3 files changed

+8
-5
lines changed

src/ngx_http_redirectionio_module.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ static ngx_int_t ngx_http_redirectionio_create_ctx_handler(ngx_http_request_t *r
232232
ctx->project_key.len = 0;
233233
ctx->scheme.len = 0;
234234
ctx->host.len = 0;
235+
ctx->backend_response_status_code = 0;
235236

236237
if (ngx_http_complex_value(r, conf->project_key, &ctx->project_key) != NGX_OK) {
237238
return NGX_DECLINED;
@@ -404,7 +405,7 @@ static ngx_int_t ngx_http_redirectionio_log_handler(ngx_http_request_t *r) {
404405
return NGX_DECLINED;
405406
}
406407

407-
should_log = redirectionio_action_should_log_request(ctx->action, conf->enable_logs != NGX_HTTP_REDIRECTIONIO_OFF, r->headers_out.status);
408+
should_log = redirectionio_action_should_log_request(ctx->action, conf->enable_logs != NGX_HTTP_REDIRECTIONIO_OFF, ctx->backend_response_status_code);
408409

409410
if (!should_log) {
410411
return NGX_DECLINED;

src/ngx_http_redirectionio_module.h

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ typedef struct {
8282
struct REDIRECTIONIO_Action *action;
8383
struct REDIRECTIONIO_HeaderMap *response_headers;
8484
struct REDIRECTIONIO_FilterBodyAction *body_filter;
85+
ngx_uint_t backend_response_status_code;
8586

8687
ngx_uint_t connection_error;
8788
ngx_uint_t wait_for_connection;

src/ngx_http_redirectionio_module_filter.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ ngx_int_t ngx_http_redirectionio_match_on_response_status_header_filter(ngx_http
3232
}
3333

3434
// Copy string
35-
redirect_status_code = redirectionio_action_get_status_code(ctx->action, r->headers_out.status);
35+
ctx->backend_response_status_code = r->headers_out.status;
36+
redirect_status_code = redirectionio_action_get_status_code(ctx->action, ctx->backend_response_status_code);
3637

3738
if (redirect_status_code == 0) {
3839
return ngx_http_redirectionio_headers_filter(r);
@@ -100,8 +101,8 @@ ngx_int_t ngx_http_redirectionio_headers_filter(ngx_http_request_t *r) {
100101
// Copy specific headers
101102
ngx_http_redirectionio_header_content_type_read(r, &header_map);
102103

103-
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "http redirectionio filtering on response status code %d", r->headers_out.status);
104-
header_map = (struct REDIRECTIONIO_HeaderMap *)redirectionio_action_header_filter_filter(ctx->action, header_map, r->headers_out.status, conf->show_rule_ids == NGX_HTTP_REDIRECTIONIO_ON);
104+
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "http redirectionio filtering on response status code %d", ctx->backend_response_status_code);
105+
header_map = (struct REDIRECTIONIO_HeaderMap *)redirectionio_action_header_filter_filter(ctx->action, header_map, ctx->backend_response_status_code, conf->show_rule_ids == NGX_HTTP_REDIRECTIONIO_ON);
105106

106107
if (header_map == NULL) {
107108
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "http redirectionio no filter to add");
@@ -197,7 +198,7 @@ static ngx_int_t ngx_http_redirectionio_create_filter_body(ngx_http_request_t *r
197198
}
198199

199200
// Create body filter
200-
ctx->body_filter = (struct REDIRECTIONIO_FilterBodyAction *)redirectionio_action_body_filter_create(ctx->action, r->headers_out.status);
201+
ctx->body_filter = (struct REDIRECTIONIO_FilterBodyAction *)redirectionio_action_body_filter_create(ctx->action, ctx->backend_response_status_code);
201202

202203
if (ctx->body_filter != NULL) {
203204
// Remove content length header

0 commit comments

Comments
 (0)