Skip to content

Commit 9de29a8

Browse files
committed
Use correct response data for apache2, add better stability when preforking
1 parent 8135869 commit 9de29a8

File tree

3 files changed

+51
-22
lines changed

3 files changed

+51
-22
lines changed

Diff for: src/mod_redirectionio.c

+40-20
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,34 @@ static int redirectionio_match_handler(request_rec *r) {
8181
return DECLINED;
8282
}
8383

84+
// Do not match against internal redirect
85+
if (r->prev) {
86+
return DECLINED;
87+
}
88+
89+
if (config->connection_pool == NULL) {
90+
if (apr_reslist_create(
91+
&config->connection_pool,
92+
RIO_MIN_CONNECTIONS,
93+
RIO_KEEP_CONNECTIONS,
94+
RIO_MAX_CONNECTIONS,
95+
0,
96+
redirectionio_pool_construct,
97+
redirectionio_pool_destruct,
98+
config,
99+
config->pool
100+
) != APR_SUCCESS) {
101+
ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r, "mod_redirectionio: Failed to initialize resource pool, disabling redirectionio.");
102+
103+
config->enable = 0;
104+
105+
return DECLINED;
106+
}
107+
108+
apr_reslist_timeout_set(config->connection_pool, RIO_TIMEOUT);
109+
apr_pool_cleanup_register(config->pool, config->connection_pool, redirectionio_child_exit, redirectionio_child_exit);
110+
}
111+
84112
// Create context
85113
redirectionio_context *ctx = ap_get_module_config(r->request_config, &redirectionio_module);
86114

@@ -96,6 +124,8 @@ static int redirectionio_match_handler(request_rec *r) {
96124
return DECLINED;
97125
}
98126

127+
ctx->matched_rule_id = NULL;
128+
ctx->target = NULL;
99129
ctx->status = 0;
100130
ctx->match_on_response_status = 0;
101131
ctx->is_redirected = 0;
@@ -446,6 +476,14 @@ static apr_status_t redirectionio_create_connection(redirectionio_connection *co
446476
return rv;
447477
}
448478

479+
rv = apr_socket_opt_set(conn->rio_sock, APR_SO_KEEPALIVE, 1);
480+
481+
if (rv != APR_SUCCESS) {
482+
ap_log_perror(APLOG_MARK, APLOG_ERR, 0, pool, "mod_redirectionio: Error setting socket keepalive: %s", apr_strerror(rv, errbuf, sizeof(errbuf)));
483+
484+
return rv;
485+
}
486+
449487
rv = apr_socket_opt_set(conn->rio_sock, APR_TCP_NODELAY, 1);
450488

451489
if (rv != APR_SUCCESS) {
@@ -554,26 +592,8 @@ static void *merge_redirectionio_dir_conf(apr_pool_t *pool, void *parent, void *
554592
conf->pass_set = conf_current->pass_set;
555593
}
556594

557-
if (apr_reslist_create(
558-
&conf->connection_pool,
559-
RIO_MIN_CONNECTIONS,
560-
RIO_KEEP_CONNECTIONS,
561-
RIO_MAX_CONNECTIONS,
562-
0,
563-
redirectionio_pool_construct,
564-
redirectionio_pool_destruct,
565-
conf,
566-
pool
567-
) != APR_SUCCESS) {
568-
ap_log_perror(APLOG_MARK, APLOG_CRIT, 0, pool, "mod_redirectionio: Failed to initialize resource pool, disabling redirectionio.");
569-
570-
conf->enable = 0;
571-
572-
return conf;
573-
}
574-
575-
apr_reslist_timeout_set(conf->connection_pool, RIO_TIMEOUT);
576-
apr_pool_cleanup_register(pool, conf->connection_pool, redirectionio_child_exit, redirectionio_child_exit);
595+
conf->pool = pool;
596+
conf->connection_pool = NULL;
577597

578598
return conf;
579599
}

Diff for: src/mod_redirectionio.h

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ typedef struct {
4040
int enable_logs;
4141
int pass_set;
4242
apr_reslist_t *connection_pool;
43+
apr_pool_t *pool;
4344
} redirectionio_config;
4445

4546
typedef struct {

Diff for: src/redirectionio_protocol.c

+10-2
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,20 @@ apr_status_t redirectionio_protocol_match(redirectionio_connection *conn, redire
9696

9797
apr_status_t redirectionio_protocol_log(redirectionio_connection *conn, redirectionio_context *ctx, request_rec *r, const char *project_key) {
9898
apr_size_t wlen, clen;
99-
const char *location = apr_table_get(r->headers_out, "Location");
99+
const char *location;
100100
const char *user_agent = apr_table_get(r->headers_in, "User-Agent");
101101
const char *referer = apr_table_get(r->headers_in, "Referer");
102102
const char *matched_rule_id = ctx->matched_rule_id;
103103
apr_status_t rv;
104104
char *dst;
105+
request_rec *response = r;
106+
107+
// Only trust last response for data
108+
while (response->next) {
109+
response = response->next;
110+
}
111+
112+
location = apr_table_get(response->headers_out, "Location");
105113

106114
if (location == NULL) {
107115
location = "";
@@ -144,7 +152,7 @@ apr_status_t redirectionio_protocol_log(redirectionio_connection *conn, redirect
144152
r->hostname,
145153
matched_rule_id,
146154
location,
147-
r->status,
155+
response->status,
148156
user_agent,
149157
referer,
150158
r->method,

0 commit comments

Comments
 (0)