Skip to content

Commit d8690ff

Browse files
committed
WIP Fixing tests for nginx
1 parent 90694d1 commit d8690ff

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

src/ngx_http_redirectionio_module_filter.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ static ngx_chain_t* ngx_http_redirectionio_body_filter_replace(struct REDIRECTIO
44

55
static void ngx_http_redirectionio_response_headers_cleanup(void *response_headers);
66

7+
static ngx_int_t ngx_http_redirectionio_create_filter_body(ngx_http_request_t *r);
8+
79
ngx_int_t ngx_http_redirectionio_match_on_response_status_header_filter(ngx_http_request_t *r) {
810
ngx_http_redirectionio_ctx_t *ctx;
911
ngx_http_redirectionio_conf_t *conf;
@@ -34,7 +36,7 @@ ngx_int_t ngx_http_redirectionio_match_on_response_status_header_filter(ngx_http
3436

3537
r->headers_out.status = redirect_status_code;
3638

37-
return ngx_http_special_response_handler(r, r->headers_out.status);
39+
return ngx_http_redirectionio_headers_filter(r);
3840
}
3941

4042
ngx_int_t ngx_http_redirectionio_headers_filter(ngx_http_request_t *r) {
@@ -99,7 +101,7 @@ ngx_int_t ngx_http_redirectionio_headers_filter(ngx_http_request_t *r) {
99101
first_header = (struct REDIRECTIONIO_HeaderMap *)redirectionio_action_header_filter_filter(ctx->action, first_header, r->headers_out.status);
100102

101103
if (first_header == NULL) {
102-
return ngx_http_next_header_filter(r);
104+
return ngx_http_redirectionio_create_filter_body(r);
103105
}
104106

105107
cln = ngx_pool_cleanup_add(r->pool, 0);
@@ -163,6 +165,22 @@ ngx_int_t ngx_http_redirectionio_headers_filter(ngx_http_request_t *r) {
163165
first_header = first_header->next;
164166
}
165167

168+
return ngx_http_redirectionio_create_filter_body(r);
169+
}
170+
171+
static ngx_int_t ngx_http_redirectionio_create_filter_body(ngx_http_request_t *r) {
172+
ngx_http_redirectionio_ctx_t *ctx;
173+
174+
ctx = ngx_http_get_module_ctx(r, ngx_http_redirectionio_module);
175+
176+
if (ctx == NULL) {
177+
return ngx_http_next_header_filter(r);
178+
}
179+
180+
if (ctx->action == NULL) {
181+
return ngx_http_next_header_filter(r);
182+
}
183+
166184
// Create body filter
167185
ctx->body_filter = (struct REDIRECTIONIO_FilterBodyAction *)redirectionio_action_body_filter_create(ctx->action, r->headers_out.status);
168186

src/ngx_http_redirectionio_module_pool.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ void ngx_http_redirectionio_read_handler(ngx_event_t *rev) {
181181
ctx->connection_error = 1;
182182
ctx->read_handler(rev, NULL);
183183

184-
ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0, "[redirectionio] connection error while reading length, skipping module for this request");
184+
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "[redirectionio] connection error while reading length, skipping module for this request");
185185

186186
return;
187187
}
@@ -194,12 +194,11 @@ void ngx_http_redirectionio_read_handler(ngx_event_t *rev) {
194194
ctx->connection_error = 1;
195195
ctx->read_handler(rev, NULL);
196196

197-
ngx_log_error(NGX_LOG_ERR, ngx_cycle->log, 0, "[redirectionio] connection error while reading length, skipping module for this request");
197+
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "[redirectionio] connection error while reading length, skipping module for this request");
198198

199199
return;
200200
}
201201

202-
*(read + rlen) = '\0';
203202
ctx->read_handler(rev, (const char *)read);
204203
}
205204

@@ -243,5 +242,7 @@ static ngx_int_t ngx_http_redirectionio_read_string(ngx_connection_t *c, char *s
243242
srlen = buf_size - sdrlen;
244243
}
245244

245+
*(string + buf_size) = '\0';
246+
246247
return NGX_OK;
247248
}

0 commit comments

Comments
 (0)