Skip to content

Commit c5135a0

Browse files
committed
change: removed compatibility code for unsupported NGINX versions (< 1.6.0).
1 parent 947fa00 commit c5135a0

23 files changed

+57
-344
lines changed

src/ngx_http_lua_accessby.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,6 @@ ngx_http_lua_access_handler(ngx_http_request_t *r)
145145
ngx_http_lua_generic_phase_post_read);
146146

147147
if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
148-
#if (nginx_version < 1002006) || \
149-
(nginx_version >= 1003000 && nginx_version < 1003009)
150-
r->main->count--;
151-
#endif
152-
153148
return rc;
154149
}
155150

src/ngx_http_lua_bodyfilterby.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,7 @@ ngx_http_lua_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
316316
return NGX_ERROR;
317317
}
318318

319-
#if nginx_version >= 1001004
320319
ngx_chain_update_chains(r->pool,
321-
#else
322-
ngx_chain_update_chains(
323-
#endif
324320
&ctx->free_bufs, &ctx->busy_bufs, &out,
325321
(ngx_buf_tag_t) &ngx_http_lua_module);
326322

src/ngx_http_lua_common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
#endif
6565

6666
#ifndef NGX_HAVE_SHA1
67-
# if (nginx_version >= 1011002)
67+
# if defined(nginx_version) && (nginx_version >= 1011002)
6868
# define NGX_HAVE_SHA1 1
6969
# endif
7070
#endif
@@ -256,7 +256,7 @@ struct ngx_http_lua_main_conf_s {
256256
of reqeusts */
257257
ngx_uint_t malloc_trim_req_count;
258258

259-
#if nginx_version >= 1011011
259+
#if defined(nginx_version) && (nginx_version >= 1011011)
260260
/* the following 2 fields are only used by ngx.req.raw_headers() for now */
261261
ngx_buf_t **busy_buf_ptrs;
262262
ngx_int_t busy_buf_ptr_count;

src/ngx_http_lua_consts.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,8 @@ ngx_http_lua_inject_http_consts(lua_State *L)
119119
lua_pushinteger(L, NGX_HTTP_MOVED_TEMPORARILY);
120120
lua_setfield(L, -2, "HTTP_MOVED_TEMPORARILY");
121121

122-
#if defined(nginx_version) && nginx_version >= 8042
123122
lua_pushinteger(L, NGX_HTTP_SEE_OTHER);
124123
lua_setfield(L, -2, "HTTP_SEE_OTHER");
125-
#endif
126124

127125
lua_pushinteger(L, NGX_HTTP_PERMANENT_REDIRECT);
128126
lua_setfield(L, -2, "HTTP_PERMANENT_REDIRECT");

src/ngx_http_lua_contentby.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,6 @@ ngx_http_lua_content_handler(ngx_http_request_t *r)
202202
ngx_http_lua_content_phase_post_read);
203203

204204
if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
205-
#if (nginx_version < 1002006) || \
206-
(nginx_version >= 1003000 && nginx_version < 1003009)
207-
r->main->count--;
208-
#endif
209205
return rc;
210206
}
211207

src/ngx_http_lua_directive.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -479,10 +479,6 @@ ngx_http_lua_rewrite_by_lua(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
479479

480480
dd("enter");
481481

482-
#if defined(nginx_version) && nginx_version >= 8042 && nginx_version <= 8053
483-
return "does not work with " NGINX_VER;
484-
#endif
485-
486482
/* must specify a content handler */
487483
if (cmd->post == NULL) {
488484
return NGX_CONF_ERROR;
@@ -1437,12 +1433,12 @@ ngx_http_lua_conf_read_lua_token(ngx_conf_t *cf,
14371433
ngx_uint_t start_line;
14381434
ngx_str_t *word;
14391435
ngx_buf_t *b;
1440-
#if nginx_version >= 1009002
1436+
#if defined(nginx_version) && (nginx_version >= 1009002)
14411437
ngx_buf_t *dump;
14421438
#endif
14431439

14441440
b = cf->conf_file->buffer;
1445-
#if nginx_version >= 1009002
1441+
#if defined(nginx_version) && (nginx_version >= 1009002)
14461442
dump = cf->conf_file->dump;
14471443
#endif
14481444
start = b->pos;
@@ -1513,7 +1509,7 @@ ngx_http_lua_conf_read_lua_token(ngx_conf_t *cf,
15131509
b->last = b->start + len + n;
15141510
start = b->start;
15151511

1516-
#if nginx_version >= 1009002
1512+
#if defined(nginx_version) && (nginx_version >= 1009002)
15171513
if (dump) {
15181514
dump->last = ngx_cpymem(dump->last, b->start + len, size);
15191515
}

src/ngx_http_lua_headers.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static int ngx_http_lua_ngx_req_raw_header(lua_State *L);
2222
static int ngx_http_lua_ngx_req_header_set_helper(lua_State *L);
2323
static int ngx_http_lua_ngx_resp_get_headers(lua_State *L);
2424
static int ngx_http_lua_ngx_req_header_set(lua_State *L);
25-
#if nginx_version >= 1011011
25+
#if defined(nginx_version) && (nginx_version >= 1011011)
2626
void ngx_http_lua_ngx_raw_header_cleanup(void *data);
2727
#endif
2828

@@ -102,7 +102,7 @@ ngx_http_lua_ngx_req_raw_header(lua_State *L)
102102
size_t size;
103103
ngx_buf_t *b, *first = NULL;
104104
ngx_int_t i, j;
105-
#if nginx_version >= 1011011
105+
#if defined(nginx_version) && (nginx_version >= 1011011)
106106
ngx_buf_t **bb;
107107
ngx_chain_t *cl;
108108
ngx_http_lua_main_conf_t *lmcf;
@@ -123,7 +123,7 @@ ngx_http_lua_ngx_req_raw_header(lua_State *L)
123123
return luaL_error(L, "no request object found");
124124
}
125125

126-
#if nginx_version >= 1011011
126+
#if defined(nginx_version) && (nginx_version >= 1011011)
127127
lmcf = ngx_http_get_module_main_conf(r, ngx_http_lua_module);
128128
#endif
129129

@@ -143,7 +143,7 @@ ngx_http_lua_ngx_req_raw_header(lua_State *L)
143143
dd("hc->nbusy: %d", (int) hc->nbusy);
144144

145145
if (hc->nbusy) {
146-
#if nginx_version >= 1011011
146+
#if defined(nginx_version) && (nginx_version >= 1011011)
147147
dd("hc->busy: %p %p %p %p", hc->busy->buf->start, hc->busy->buf->pos,
148148
hc->busy->buf->last, hc->busy->buf->end);
149149
#else
@@ -185,7 +185,7 @@ ngx_http_lua_ngx_req_raw_header(lua_State *L)
185185
dd("size: %d", (int) size);
186186

187187
if (hc->nbusy) {
188-
#if nginx_version >= 1011011
188+
#if defined(nginx_version) && (nginx_version >= 1011011)
189189
if (hc->nbusy > lmcf->busy_buf_ptr_count) {
190190
if (lmcf->busy_buf_ptrs) {
191191
ngx_free(lmcf->busy_buf_ptrs);
@@ -208,7 +208,7 @@ ngx_http_lua_ngx_req_raw_header(lua_State *L)
208208
#endif
209209
b = NULL;
210210

211-
#if nginx_version >= 1011011
211+
#if defined(nginx_version) && (nginx_version >= 1011011)
212212
bb = lmcf->busy_buf_ptrs;
213213
for (i = hc->nbusy; i > 0; i--) {
214214
b = bb[i - 1];
@@ -291,7 +291,7 @@ ngx_http_lua_ngx_req_raw_header(lua_State *L)
291291

292292
if (hc->nbusy) {
293293

294-
#if nginx_version >= 1011011
294+
#if defined(nginx_version) && (nginx_version >= 1011011)
295295
bb = lmcf->busy_buf_ptrs;
296296
for (i = hc->nbusy - 1; i >= 0; i--) {
297297
b = bb[i];
@@ -1138,7 +1138,7 @@ ngx_http_lua_ffi_get_resp_header(ngx_http_request_t *r,
11381138
}
11391139

11401140

1141-
#if nginx_version >= 1011011
1141+
#if defined(nginx_version) && (nginx_version >= 1011011)
11421142
void
11431143
ngx_http_lua_ngx_raw_header_cleanup(void *data)
11441144
{

src/ngx_http_lua_headers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
void ngx_http_lua_inject_resp_header_api(lua_State *L);
1616
void ngx_http_lua_inject_req_header_api(lua_State *L);
1717
void ngx_http_lua_create_headers_metatable(ngx_log_t *log, lua_State *L);
18-
#if nginx_version >= 1011011
18+
#if defined(nginx_version) && (nginx_version >= 1011011)
1919
void ngx_http_lua_ngx_raw_header_cleanup(void *data);
2020
#endif
2121

src/ngx_http_lua_headers_in.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,17 @@ static ngx_http_lua_set_header_t ngx_http_lua_set_handlers[] = {
5656
offsetof(ngx_http_headers_in_t, if_modified_since),
5757
ngx_http_set_builtin_header },
5858

59-
#if defined(nginx_version) && nginx_version >= 9002
6059
{ ngx_string("If-Unmodified-Since"),
6160
offsetof(ngx_http_headers_in_t, if_unmodified_since),
6261
ngx_http_set_builtin_header },
63-
#endif
6462

65-
#if defined(nginx_version) && nginx_version >= 1003003
6663
{ ngx_string("If-Match"),
6764
offsetof(ngx_http_headers_in_t, if_match),
6865
ngx_http_set_builtin_header },
6966

7067
{ ngx_string("If-None-Match"),
7168
offsetof(ngx_http_headers_in_t, if_none_match),
7269
ngx_http_set_builtin_header },
73-
#endif
7470

7571
{ ngx_string("User-Agent"),
7672
offsetof(ngx_http_headers_in_t, user_agent),
@@ -104,11 +100,9 @@ static ngx_http_lua_set_header_t ngx_http_lua_set_handlers[] = {
104100
offsetof(ngx_http_headers_in_t, expect),
105101
ngx_http_set_builtin_header },
106102

107-
#if defined(nginx_version) && nginx_version >= 1003013
108103
{ ngx_string("Upgrade"),
109104
offsetof(ngx_http_headers_in_t, upgrade),
110105
ngx_http_set_builtin_header },
111-
#endif
112106

113107
#if (NGX_HTTP_GZIP)
114108
{ ngx_string("Accept-Encoding"),

src/ngx_http_lua_initworkerby.c

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,8 @@ ngx_http_lua_init_worker(ngx_cycle_t *cycle)
114114

115115
ngx_memcpy(fake_cycle, cycle, sizeof(ngx_cycle_t));
116116

117-
#if defined(nginx_version) && nginx_version >= 9007
118-
119117
ngx_queue_init(&fake_cycle->reusable_connections_queue);
120118

121-
#endif
122-
123119
if (ngx_array_init(&fake_cycle->listening, cycle->pool,
124120
cycle->listening.nelts || 1,
125121
sizeof(ngx_listening_t))
@@ -128,17 +124,13 @@ ngx_http_lua_init_worker(ngx_cycle_t *cycle)
128124
goto failed;
129125
}
130126

131-
#if defined(nginx_version) && nginx_version >= 1003007
132-
133127
if (ngx_array_init(&fake_cycle->paths, cycle->pool, cycle->paths.nelts || 1,
134128
sizeof(ngx_path_t *))
135129
!= NGX_OK)
136130
{
137131
goto failed;
138132
}
139133

140-
#endif
141-
142134
part = &cycle->open_files.part;
143135
ofile = part->elts;
144136

@@ -302,26 +294,11 @@ ngx_http_lua_init_worker(ngx_cycle_t *cycle)
302294

303295
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
304296

305-
#if defined(nginx_version) && nginx_version >= 1003014
306-
307-
# if nginx_version >= 1009000
308-
297+
#if defined(nginx_version) && (nginx_version >= 1009000)
309298
ngx_set_connection_log(r->connection, clcf->error_log);
310299

311-
# else
312-
313-
ngx_http_set_connection_log(r->connection, clcf->error_log);
314-
315-
# endif
316-
317300
#else
318-
319-
c->log->file = clcf->error_log->file;
320-
321-
if (!(c->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {
322-
c->log->log_level = clcf->error_log->log_level;
323-
}
324-
301+
ngx_http_set_connection_log(r->connection, clcf->error_log);
325302
#endif
326303

327304
ctx = ngx_http_lua_create_ctx(r);

src/ngx_http_lua_module.c

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static ngx_conf_post_t ngx_http_lua_lowat_post =
5858
static volatile ngx_cycle_t *ngx_http_lua_prev_cycle = NULL;
5959

6060

61-
#if (NGX_HTTP_SSL) && defined(nginx_version) && nginx_version >= 1001013
61+
#if (NGX_HTTP_SSL)
6262

6363
static ngx_conf_bitmask_t ngx_http_lua_ssl_protocols[] = {
6464
{ ngx_string("SSLv2"), NGX_SSL_SSLv2 },
@@ -515,17 +515,13 @@ static ngx_command_t ngx_http_lua_cmds[] = {
515515

516516
#if (NGX_HTTP_SSL)
517517

518-
# if defined(nginx_version) && nginx_version >= 1001013
519-
520518
{ ngx_string("lua_ssl_protocols"),
521519
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
522520
ngx_conf_set_bitmask_slot,
523521
NGX_HTTP_LOC_CONF_OFFSET,
524522
offsetof(ngx_http_lua_loc_conf_t, ssl_protocols),
525523
&ngx_http_lua_ssl_protocols },
526524

527-
# endif
528-
529525
{ ngx_string("lua_ssl_ciphers"),
530526
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
531527
ngx_conf_set_str_slot,
@@ -650,7 +646,7 @@ ngx_http_lua_init(ngx_conf_t *cf)
650646
volatile ngx_cycle_t *saved_cycle;
651647
ngx_http_core_main_conf_t *cmcf;
652648
ngx_http_lua_main_conf_t *lmcf;
653-
#if nginx_version >= 1011011
649+
#if defined(nginx_version) && (nginx_version >= 1011011)
654650
ngx_pool_cleanup_t *cln;
655651
#endif
656652
ngx_str_t name = ngx_string("host");
@@ -754,7 +750,7 @@ ngx_http_lua_init(ngx_conf_t *cf)
754750
ngx_http_lua_pipe_init();
755751
#endif
756752

757-
#if nginx_version >= 1011011
753+
#if defined(nginx_version) && (nginx_version >= 1011011)
758754
cln = ngx_pool_cleanup_add(cf->pool, 0);
759755
if (cln == NULL) {
760756
return NGX_ERROR;
@@ -1232,15 +1228,11 @@ ngx_http_lua_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
12321228

12331229
#if (NGX_HTTP_SSL)
12341230

1235-
# if defined(nginx_version) && nginx_version >= 1001013
1236-
12371231
ngx_conf_merge_bitmask_value(conf->ssl_protocols, prev->ssl_protocols,
12381232
(NGX_CONF_BITMASK_SET|NGX_SSL_SSLv3
12391233
|NGX_SSL_TLSv1|NGX_SSL_TLSv1_1
12401234
|NGX_SSL_TLSv1_2));
12411235

1242-
# endif
1243-
12441236
ngx_conf_merge_str_value(conf->ssl_ciphers, prev->ssl_ciphers,
12451237
"DEFAULT");
12461238

@@ -1328,26 +1320,13 @@ ngx_http_lua_set_ssl(ngx_conf_t *cf, ngx_http_lua_loc_conf_t *llcf)
13281320
return NGX_ERROR;
13291321
}
13301322

1331-
if (llcf->ssl_trusted_certificate.len) {
1332-
1333-
#if defined(nginx_version) && nginx_version >= 1003007
1334-
1335-
if (ngx_ssl_trusted_certificate(cf, llcf->ssl,
1336-
&llcf->ssl_trusted_certificate,
1337-
llcf->ssl_verify_depth)
1338-
!= NGX_OK)
1339-
{
1340-
return NGX_ERROR;
1341-
}
1342-
1343-
#else
1344-
1345-
ngx_log_error(NGX_LOG_CRIT, cf->log, 0, "at least nginx 1.3.7 is "
1346-
"required for the \"lua_ssl_trusted_certificate\" "
1347-
"directive");
1323+
if (llcf->ssl_trusted_certificate.len
1324+
&& ngx_ssl_trusted_certificate(cf, llcf->ssl,
1325+
&llcf->ssl_trusted_certificate,
1326+
llcf->ssl_verify_depth)
1327+
!= NGX_OK)
1328+
{
13481329
return NGX_ERROR;
1349-
1350-
#endif
13511330
}
13521331

13531332
dd("ssl crl: %.*s", (int) llcf->ssl_crl.len, llcf->ssl_crl.data);

src/ngx_http_lua_req_body.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,6 @@ ngx_http_lua_ngx_req_read_body(lua_State *L)
114114

115115
rc = ngx_http_read_client_request_body(r, ngx_http_lua_req_body_post_read);
116116

117-
#if (nginx_version < 1002006) || \
118-
(nginx_version >= 1003000 && nginx_version < 1003009)
119-
r->main->count--;
120-
#endif
121-
122117
if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
123118
ctx->exit_code = rc;
124119
ctx->exited = 1;
@@ -130,11 +125,8 @@ ngx_http_lua_ngx_req_read_body(lua_State *L)
130125
return lua_yield(L, 0);
131126
}
132127

133-
#if (nginx_version >= 1002006 && nginx_version < 1003000) || \
134-
nginx_version >= 1003009
135128
r->main->count--;
136129
dd("decrement r->main->count: %d", (int) r->main->count);
137-
#endif
138130

139131
if (rc == NGX_AGAIN) {
140132
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,

0 commit comments

Comments
 (0)