8
8
9
9
10
10
typedef struct {
11
- nxt_str_t share ;
11
+ nxt_var_t * share ;
12
12
#if (NXT_HAVE_OPENAT2 )
13
13
nxt_var_t * chroot ;
14
14
nxt_uint_t resolve ;
15
+ u_char * fname ;
15
16
#endif
16
17
nxt_http_route_rule_t * types ;
17
18
uint8_t is_const ; /* 1 bit */
@@ -20,6 +21,7 @@ typedef struct {
20
21
21
22
typedef struct {
22
23
nxt_http_action_t * action ;
24
+ nxt_str_t share ;
23
25
#if (NXT_HAVE_OPENAT2 )
24
26
nxt_str_t chroot ;
25
27
#endif
@@ -59,7 +61,7 @@ nxt_http_static_init(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
59
61
nxt_http_action_t * action , nxt_http_action_conf_t * acf )
60
62
{
61
63
nxt_mp_t * mp ;
62
- nxt_str_t * str , value ;
64
+ nxt_str_t str ;
63
65
nxt_http_static_conf_t * conf ;
64
66
65
67
mp = tmcf -> router_conf -> mem_pool ;
@@ -72,17 +74,19 @@ nxt_http_static_init(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
72
74
action -> handler = nxt_http_static ;
73
75
action -> u .conf = conf ;
74
76
75
- nxt_conf_get_string (acf -> share , & value );
77
+ nxt_conf_get_string (acf -> share , & str );
76
78
77
- str = nxt_str_dup ( mp , & conf -> share , & value );
78
- if (nxt_slow_path (str == NULL )) {
79
+ conf -> share = nxt_var_compile ( & str , mp , 1 );
80
+ if (nxt_slow_path (conf -> share == NULL )) {
79
81
return NXT_ERROR ;
80
82
}
81
83
82
- conf -> is_const = 1 ;
84
+ conf -> is_const = nxt_var_is_const ( conf -> share ) ;
83
85
84
86
#if (NXT_HAVE_OPENAT2 )
85
87
if (acf -> chroot .length > 0 ) {
88
+ nxt_str_t chr , shr ;
89
+
86
90
if (nxt_is_var (& acf -> chroot )) {
87
91
conf -> is_const = 0 ;
88
92
}
@@ -91,6 +95,13 @@ nxt_http_static_init(nxt_task_t *task, nxt_router_temp_conf_t *tmcf,
91
95
if (nxt_slow_path (conf -> chroot == NULL )) {
92
96
return NXT_ERROR ;
93
97
}
98
+
99
+ if (conf -> is_const ) {
100
+ nxt_var_raw (conf -> chroot , & chr );
101
+ nxt_var_raw (conf -> share , & shr );
102
+
103
+ conf -> fname = nxt_http_static_chroot_match (chr .start , shr .start );
104
+ }
94
105
}
95
106
96
107
if (acf -> follow_symlinks != NULL
@@ -155,7 +166,12 @@ nxt_http_static(nxt_task_t *task, nxt_http_request_t *r,
155
166
156
167
conf = action -> u .conf ;
157
168
158
- #if (NXT_DEBUG && NXT_HAVE_OPENAT2 )
169
+ #if (NXT_DEBUG )
170
+ nxt_str_t shr ;
171
+
172
+ nxt_var_raw (conf -> share , & shr );
173
+
174
+ #if (NXT_HAVE_OPENAT2 )
159
175
nxt_str_t chr ;
160
176
161
177
if (conf -> chroot != NULL ) {
@@ -165,11 +181,11 @@ nxt_http_static(nxt_task_t *task, nxt_http_request_t *r,
165
181
nxt_str_set (& chr , "" );
166
182
}
167
183
168
- nxt_debug (task , "http static: \"%V\" (chroot: \"%V\")" , & conf -> share , & chr );
169
-
184
+ nxt_debug (task , "http static: \"%V\" (chroot: \"%V\")" , & shr , & chr );
170
185
#else
171
- nxt_debug (task , "http static: \"%V\"" , & conf -> share );
186
+ nxt_debug (task , "http static: \"%V\"" , & shr );
172
187
#endif
188
+ #endif /* NXT_DEBUG */
173
189
174
190
ctx = nxt_mp_zget (r -> mem_pool , sizeof (nxt_http_static_ctx_t ));
175
191
if (nxt_slow_path (ctx == NULL )) {
@@ -180,6 +196,8 @@ nxt_http_static(nxt_task_t *task, nxt_http_request_t *r,
180
196
ctx -> need_body = need_body ;
181
197
182
198
if (conf -> is_const ) {
199
+ nxt_var_raw (conf -> share , & ctx -> share );
200
+
183
201
#if (NXT_HAVE_OPENAT2 )
184
202
if (conf -> chroot != NULL ) {
185
203
nxt_var_raw (conf -> chroot , & ctx -> chroot );
@@ -194,8 +212,12 @@ nxt_http_static(nxt_task_t *task, nxt_http_request_t *r,
194
212
goto fail ;
195
213
}
196
214
215
+ nxt_var_query (task , r -> var_query , conf -> share , & ctx -> share );
216
+
197
217
#if (NXT_HAVE_OPENAT2 )
198
- nxt_var_query (task , r -> var_query , conf -> chroot , & ctx -> chroot );
218
+ if (conf -> chroot != NULL ) {
219
+ nxt_var_query (task , r -> var_query , conf -> chroot , & ctx -> chroot );
220
+ }
199
221
#endif
200
222
201
223
nxt_var_query_resolve (task , r -> var_query , ctx ,
@@ -220,7 +242,7 @@ nxt_http_static_send_ready(nxt_task_t *task, void *obj, void *data)
220
242
struct tm tm ;
221
243
nxt_buf_t * fb ;
222
244
nxt_int_t ret ;
223
- nxt_str_t index , exten , * mtype ;
245
+ nxt_str_t * shr , exten , * mtype ;
224
246
nxt_uint_t level ;
225
247
nxt_file_t * f , file ;
226
248
nxt_file_info_t fi ;
@@ -233,56 +255,58 @@ nxt_http_static_send_ready(nxt_task_t *task, void *obj, void *data)
233
255
nxt_http_static_ctx_t * ctx ;
234
256
nxt_http_static_conf_t * conf ;
235
257
258
+ static nxt_str_t index = nxt_string ("index.html" );
259
+
236
260
r = obj ;
237
261
ctx = data ;
238
262
action = ctx -> action ;
239
263
conf = action -> u .conf ;
240
-
241
- if (r -> path -> start [r -> path -> length - 1 ] == '/' ) {
242
- /* TODO: dynamic index setting. */
243
- nxt_str_set (& index , "index.html" );
244
- nxt_str_set (& exten , ".html" );
245
-
246
- } else {
247
- nxt_str_set (& index , "" );
248
- nxt_str_null (& exten );
249
- }
264
+ rtcf = r -> conf -> socket_conf -> router_conf ;
250
265
251
266
f = NULL ;
267
+ mtype = NULL ;
252
268
status = NXT_HTTP_INTERNAL_SERVER_ERROR ;
253
269
254
- rtcf = r -> conf -> socket_conf -> router_conf ;
270
+ shr = & ctx -> share ;
255
271
256
- mtype = NULL ;
272
+ if (shr -> start [shr -> length - 1 ] == '/' ) {
273
+ /* TODO: dynamic index setting. */
274
+ nxt_str_set (& exten , ".html" );
257
275
258
- if (conf -> types != NULL && exten .start == NULL ) {
259
- nxt_http_static_extract_extension (r -> path , & exten );
260
- mtype = nxt_http_static_mtype_get (& rtcf -> mtypes_hash , & exten );
276
+ length = shr -> length + index .length ;
261
277
262
- ret = nxt_http_route_test_rule (r , conf -> types , mtype -> start ,
263
- mtype -> length );
264
- if (nxt_slow_path (ret == NXT_ERROR )) {
278
+ fname = nxt_mp_nget (r -> mem_pool , length + 1 );
279
+ if (nxt_slow_path (fname == NULL )) {
265
280
goto fail ;
266
281
}
267
282
268
- if (ret == 0 ) {
269
- status = NXT_HTTP_FORBIDDEN ;
270
- goto fail ;
271
- }
272
- }
283
+ p = fname ;
284
+ p = nxt_cpymem (p , shr -> start , shr -> length );
285
+ p = nxt_cpymem (p , index .start , index .length );
286
+ * p = '\0' ;
273
287
274
- length = conf -> share .length + r -> path -> length + index .length ;
288
+ } else {
289
+ if (conf -> types == NULL ) {
290
+ nxt_str_null (& exten );
275
291
276
- fname = nxt_mp_nget (r -> mem_pool , length + 1 );
277
- if (nxt_slow_path (fname == NULL )) {
278
- goto fail ;
279
- }
292
+ } else {
293
+ nxt_http_static_extract_extension (shr , & exten );
294
+ mtype = nxt_http_static_mtype_get (& rtcf -> mtypes_hash , & exten );
295
+
296
+ ret = nxt_http_route_test_rule (r , conf -> types , mtype -> start ,
297
+ mtype -> length );
298
+ if (nxt_slow_path (ret == NXT_ERROR )) {
299
+ goto fail ;
300
+ }
280
301
281
- p = fname ;
282
- p = nxt_cpymem (p , conf -> share .start , conf -> share .length );
283
- p = nxt_cpymem (p , r -> path -> start , r -> path -> length );
284
- p = nxt_cpymem (p , index .start , index .length );
285
- * p = '\0' ;
302
+ if (ret == 0 ) {
303
+ status = NXT_HTTP_FORBIDDEN ;
304
+ goto fail ;
305
+ }
306
+ }
307
+
308
+ fname = ctx -> share .start ;
309
+ }
286
310
287
311
nxt_memzero (& file , sizeof (nxt_file_t ));
288
312
@@ -299,7 +323,9 @@ nxt_http_static_send_ready(nxt_task_t *task, void *obj, void *data)
299
323
if (chr -> length > 0 ) {
300
324
resolve |= RESOLVE_IN_ROOT ;
301
325
302
- fname = nxt_http_static_chroot_match (chr -> start , file .name );
326
+ fname = conf -> is_const
327
+ ? conf -> fname
328
+ : nxt_http_static_chroot_match (chr -> start , file .name );
303
329
304
330
if (fname != NULL ) {
305
331
file .name = chr -> start ;
@@ -460,7 +486,7 @@ nxt_http_static_send_ready(nxt_task_t *task, void *obj, void *data)
460
486
- p ;
461
487
462
488
if (exten .start == NULL ) {
463
- nxt_http_static_extract_extension (r -> path , & exten );
489
+ nxt_http_static_extract_extension (shr , & exten );
464
490
}
465
491
466
492
if (mtype == NULL ) {
0 commit comments