4
4
#include "ngx_http_apisix_module.h"
5
5
6
6
7
+ static void * ngx_http_apisix_create_loc_conf (ngx_conf_t * cf );
8
+ static char * ngx_http_apisix_merge_loc_conf (ngx_conf_t * cf , void * parent ,
9
+ void * child );
10
+
11
+
12
+ static ngx_command_t ngx_http_apisix_cmds [] = {
13
+ { ngx_string ("apisix_delay_client_max_body_check" ),
14
+ NGX_HTTP_MAIN_CONF |NGX_HTTP_SRV_CONF |NGX_HTTP_LOC_CONF |NGX_CONF_FLAG ,
15
+ ngx_conf_set_flag_slot ,
16
+ NGX_HTTP_LOC_CONF_OFFSET ,
17
+ offsetof(ngx_http_apisix_loc_conf_t , delay_client_max_body_check ),
18
+ NULL },
19
+
20
+ ngx_null_command
21
+ };
22
+
23
+
7
24
static ngx_http_module_t ngx_http_apisix_module_ctx = {
8
25
NULL , /* preconfiguration */
9
26
NULL , /* postconfiguration */
@@ -14,15 +31,15 @@ static ngx_http_module_t ngx_http_apisix_module_ctx = {
14
31
NULL , /* create server configuration */
15
32
NULL , /* merge server configuration */
16
33
17
- NULL , /* create location configuration */
18
- NULL /* merge location configuration */
34
+ ngx_http_apisix_create_loc_conf , /* create location configuration */
35
+ ngx_http_apisix_merge_loc_conf /* merge location configuration */
19
36
};
20
37
21
38
22
39
ngx_module_t ngx_http_apisix_module = {
23
40
NGX_MODULE_V1 ,
24
41
& ngx_http_apisix_module_ctx , /* module context */
25
- NULL , /* module directives */
42
+ ngx_http_apisix_cmds , /* module directives */
26
43
NGX_HTTP_MODULE , /* module type */
27
44
NULL , /* init master */
28
45
NULL , /* init module */
@@ -35,6 +52,34 @@ ngx_module_t ngx_http_apisix_module = {
35
52
};
36
53
37
54
55
+ static void *
56
+ ngx_http_apisix_create_loc_conf (ngx_conf_t * cf )
57
+ {
58
+ ngx_http_apisix_loc_conf_t * conf ;
59
+
60
+ conf = ngx_pcalloc (cf -> pool , sizeof (ngx_http_apisix_loc_conf_t ));
61
+ if (conf == NULL ) {
62
+ return NULL ;
63
+ }
64
+
65
+ conf -> delay_client_max_body_check = NGX_CONF_UNSET ;
66
+
67
+ return conf ;
68
+ }
69
+
70
+
71
+ static char *
72
+ ngx_http_apisix_merge_loc_conf (ngx_conf_t * cf , void * parent , void * child )
73
+ {
74
+ ngx_http_apisix_loc_conf_t * prev = parent ;
75
+ ngx_http_apisix_loc_conf_t * conf = child ;
76
+
77
+ ngx_conf_merge_value (conf -> delay_client_max_body_check ,
78
+ prev -> delay_client_max_body_check , 0 );
79
+
80
+ return NGX_CONF_OK ;
81
+ }
82
+
38
83
39
84
#if (NGX_HTTP_SSL )
40
85
static X509 *
@@ -230,3 +275,56 @@ ngx_http_apisix_set_upstream_ssl(ngx_http_request_t *r, ngx_connection_t *c)
230
275
ngx_http_apisix_flush_ssl_error ();
231
276
}
232
277
#endif
278
+
279
+
280
+ ngx_flag_t
281
+ ngx_http_apisix_delay_client_max_body_check (ngx_http_request_t * r )
282
+ {
283
+ ngx_http_apisix_loc_conf_t * alcf ;
284
+
285
+ alcf = ngx_http_get_module_loc_conf (r , ngx_http_apisix_module );
286
+ return alcf -> delay_client_max_body_check ;
287
+ }
288
+
289
+
290
+ ngx_int_t
291
+ ngx_http_apisix_client_set_max_body_size (ngx_http_request_t * r ,
292
+ off_t bytes )
293
+ {
294
+ ngx_http_apisix_ctx_t * ctx ;
295
+
296
+ ctx = ngx_http_apisix_get_module_ctx (r );
297
+
298
+ if (ctx == NULL ) {
299
+ return NGX_ERROR ;
300
+ }
301
+
302
+ ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
303
+ "set client max body size %O" ,
304
+ ctx -> client_max_body_size );
305
+
306
+ ctx -> client_max_body_size = bytes ;
307
+
308
+ return NGX_OK ;
309
+ }
310
+
311
+
312
+ off_t
313
+ ngx_http_apisix_client_max_body_size (ngx_http_request_t * r )
314
+ {
315
+ ngx_http_apisix_ctx_t * ctx ;
316
+ ngx_http_core_loc_conf_t * clcf ;
317
+
318
+ ctx = ngx_http_get_module_ctx (r , ngx_http_apisix_module );
319
+
320
+ if (ctx != NULL && ctx -> client_max_body_size ) {
321
+ ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , r -> connection -> log , 0 ,
322
+ "get client max body size %O" ,
323
+ ctx -> client_max_body_size );
324
+ return ctx -> client_max_body_size ;
325
+ }
326
+
327
+ clcf = ngx_http_get_module_loc_conf (r , ngx_http_core_module );
328
+
329
+ return clcf -> client_max_body_size ;
330
+ }
0 commit comments