Skip to content

Commit e85f7c2

Browse files
committed
Use buffered as it works for every nginx version, fix some typos
1 parent 27c336f commit e85f7c2

5 files changed

+47
-23
lines changed

dev-build.sh

+30-1
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,41 @@
55
# https://github.com/openresty/nginx-devel-utils/blob/master/ngx-build
66
# the resulting nginx is located at ./work/nginx/sbin/nginx
77
root=`pwd`
8-
version=${1:-1.9.15}
8+
version=${1:-1.15.8}
99
module_directory="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
1010

1111
export NGX_BUILD_CC="gcc"
1212
export NGX_BUILD_JOBS=8
1313

14+
ngx-build $version \
15+
--with-cc-opt="-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2" \
16+
--with-ld-opt="-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fPIC" \
17+
--with-debug \
18+
--with-pcre-jit \
19+
--with-ipv6 \
20+
--with-http_stub_status_module \
21+
--with-http_realip_module \
22+
--with-http_auth_request_module \
23+
--with-http_v2_module \
24+
--with-http_dav_module \
25+
--with-http_slice_module \
26+
--with-threads \
27+
--with-http_addition_module \
28+
--with-http_flv_module \
29+
--with-http_geoip_module=dynamic \
30+
--with-http_gunzip_module \
31+
--with-http_gzip_static_module \
32+
--with-http_image_filter_module=dynamic \
33+
--with-http_mp4_module \
34+
--with-http_random_index_module \
35+
--with-http_secure_link_module \
36+
--with-http_sub_module \
37+
--with-http_xslt_module=dynamic \
38+
--with-mail=dynamic \
39+
--with-stream=dynamic \
40+
--add-module=$module_directory \
41+
$opts \
42+
--with-debug ||
1443
ngx-build $version \
1544
--with-cc-opt="-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2" \
1645
--with-ld-opt="-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fPIC" \

src/ngx_http_redirectionio_module.c

-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ static ngx_int_t ngx_http_redirectionio_redirect_handler(ngx_http_request_t *r);
2020
static ngx_int_t ngx_http_redirectionio_log_handler(ngx_http_request_t *r);
2121

2222
static void ngx_http_redirectionio_write_match_rule_handler(ngx_event_t *wev);
23-
2423
static void ngx_http_redirectionio_read_match_rule_handler(ngx_event_t *rev, cJSON *json);
25-
static void ngx_http_redirectionio_read_filter_headers_handler(ngx_event_t *rev, cJSON *json);
2624

2725
/**
2826
* Commands definitions

src/ngx_http_redirectionio_module_filter.c

+7-12
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,6 @@ ngx_int_t ngx_http_redirectionio_body_filter(ngx_http_request_t *r, ngx_chain_t
124124
ngx_http_redirectionio_ctx_t *ctx;
125125
ngx_http_redirectionio_conf_t *conf;
126126
ngx_int_t status;
127-
ngx_chain_t *cl;
128-
ngx_str_t buffer_str;
129127

130128
conf = ngx_http_get_module_loc_conf(r, ngx_http_redirectionio_module);
131129

@@ -151,7 +149,7 @@ ngx_int_t ngx_http_redirectionio_body_filter(ngx_http_request_t *r, ngx_chain_t
151149
// Check if we are waiting for filtering headers or connection
152150
if (ctx->wait_for_header_filtering || ctx->wait_for_connection) {
153151
// Set request is buffered to avoid its destruction by nginx
154-
r->blocked = 1;
152+
r->buffered = 1;
155153

156154
return NGX_AGAIN;
157155
}
@@ -172,7 +170,7 @@ ngx_int_t ngx_http_redirectionio_body_filter(ngx_http_request_t *r, ngx_chain_t
172170
if (status == NGX_AGAIN) {
173171
ctx->wait_for_connection = 1;
174172

175-
r->blocked = 1;
173+
r->buffered = 1;
176174

177175
return status;
178176
}
@@ -196,7 +194,7 @@ ngx_int_t ngx_http_redirectionio_body_filter(ngx_http_request_t *r, ngx_chain_t
196194
ctx->first_buffer = 0;
197195
}
198196

199-
r->blocked = 1;
197+
r->buffered = 1;
200198

201199
// Stream body
202200
return NGX_AGAIN;
@@ -345,7 +343,7 @@ static void ngx_http_redirectionio_read_filter_body_handler(ngx_event_t *rev, u_
345343
ngx_http_redirectionio_conf_t *conf;
346344
ngx_http_request_t *r;
347345
ngx_connection_t *c;
348-
ngx_chain_t *new_chain, *chain_sent;
346+
ngx_chain_t *new_chain;
349347

350348
c = rev->data;
351349
r = c->data;
@@ -376,7 +374,7 @@ static void ngx_http_redirectionio_read_filter_body_handler(ngx_event_t *rev, u_
376374

377375
ngx_http_next_body_filter(r, new_chain);
378376

379-
r->blocked = 0;
377+
r->buffered = 0;
380378

381379
ngx_http_finalize_request(r, NGX_OK);
382380

@@ -410,10 +408,7 @@ static void ngx_http_redirectionio_read_filter_body_handler(ngx_event_t *rev, u_
410408
}
411409

412410
static void ngx_http_redirectionio_finalize_request(ngx_http_request_t *r, ngx_http_redirectionio_ctx_t *ctx) {
413-
ngx_int_t status;
414-
ngx_http_redirectionio_conf_t *conf;
415-
416-
conf = ngx_http_get_module_loc_conf(r, ngx_http_redirectionio_module);
411+
ngx_int_t status;
417412

418413
if (!ctx->headers_sent) {
419414
status = ngx_http_next_header_filter(r);
@@ -434,7 +429,7 @@ static void ngx_http_redirectionio_finalize_request(ngx_http_request_t *r, ngx_h
434429
}
435430
}
436431

437-
r->blocked = 0;
432+
r->buffered = 0;
438433

439434
ngx_http_finalize_request(r, NGX_OK);
440435
}

src/ngx_http_redirectionio_module_pool.c

-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ void ngx_http_redirectionio_read_binary_handler(ngx_event_t *rev) {
230230
ngx_http_request_t *r;
231231
ngx_http_redirectionio_ctx_t *ctx;
232232
u_char *buffer;
233-
u_char read;
234233
ssize_t readed, last_readed;
235234
int64_t buffer_size;
236235

src/ngx_http_redirectionio_protocol.c

+10-7
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,12 @@ void ngx_http_redirectionio_protocol_free_log(ngx_http_redirectionio_log_t *log)
122122
}
123123

124124
void ngx_http_redirectionio_protocol_send_filter_header(ngx_connection_t *c, ngx_http_request_t *r, ngx_str_t *project_key, ngx_str_t *rule_id) {
125-
ssize_t wlen;
126125
const char *dst;
127-
ngx_str_t v;
128-
ngx_str_t encoded_headers = ngx_null_string;
126+
char *hname, *hvalue;
129127
ngx_list_part_t *part;
130128
ngx_table_elt_t *h;
131129
ngx_uint_t i;
132130
cJSON *query, *headers, *header;
133-
ngx_pool_cleanup_t *cln;
134131

135132
query = cJSON_CreateObject();
136133
headers = cJSON_CreateArray();
@@ -154,15 +151,21 @@ void ngx_http_redirectionio_protocol_send_filter_header(ngx_connection_t *c, ngx
154151
}
155152

156153
// Not used skip it
157-
if (h[i].hash == 0) {
154+
if (h[i].hash == 0 || h[i].value.len <= 0 || h[i].key.len <= 0) {
158155
continue;
159156
}
160157

158+
hname = strndup((const char *)h[i].key.data, h[i].key.len);
159+
hvalue = strndup((const char *)h[i].value.data, h[i].value.len);
160+
161161
header = cJSON_CreateObject();
162-
cJSON_AddItemToObject(header, "name", cJSON_CreateString((const char *)h[i].key.data));
163-
cJSON_AddItemToObject(header, "value", cJSON_CreateString((const char *)h[i].value.data));
162+
cJSON_AddItemToObject(header, "name", cJSON_CreateString((const char *)hname));
163+
cJSON_AddItemToObject(header, "value", cJSON_CreateString((const char *)hvalue));
164164

165165
cJSON_AddItemToArray(headers, header);
166+
167+
free(hname);
168+
free(hvalue);
166169
}
167170

168171
dst = cJSON_PrintUnformatted(query);

0 commit comments

Comments
 (0)