@@ -7,26 +7,29 @@ use std::time::Instant;
7
7
8
8
use ngx:: core;
9
9
use ngx:: ffi:: {
10
- ngx_array_push, ngx_command_t, ngx_conf_t, ngx_connection_t, ngx_event_t, ngx_http_core_module ,
11
- ngx_http_handler_pt , ngx_http_module_t , ngx_http_phases_NGX_HTTP_ACCESS_PHASE , ngx_int_t , ngx_module_t ,
12
- ngx_post_event , ngx_posted_events , ngx_posted_next_events, ngx_str_t, ngx_uint_t, NGX_CONF_TAKE1 ,
13
- NGX_HTTP_LOC_CONF , NGX_HTTP_LOC_CONF_OFFSET , NGX_HTTP_MODULE ,
10
+ ngx_array_push, ngx_command_t, ngx_conf_t, ngx_connection_t, ngx_event_t, ngx_http_handler_pt , ngx_http_module_t ,
11
+ ngx_http_phases_NGX_HTTP_ACCESS_PHASE , ngx_int_t , ngx_module_t , ngx_post_event , ngx_posted_events ,
12
+ ngx_posted_next_events, ngx_str_t, ngx_uint_t, NGX_CONF_TAKE1 , NGX_HTTP_LOC_CONF , NGX_HTTP_LOC_CONF_OFFSET ,
13
+ NGX_HTTP_MODULE ,
14
14
} ;
15
- use ngx:: http:: { self , HTTPModule , MergeConfigError } ;
15
+ use ngx:: http:: { self , HttpModule , MergeConfigError } ;
16
+ use ngx:: http:: { HttpModuleLocationConf , HttpModuleMainConf , NgxHttpCoreModule } ;
16
17
use ngx:: { http_request_handler, ngx_log_debug_http, ngx_string} ;
17
18
use tokio:: runtime:: Runtime ;
18
19
19
20
struct Module ;
20
21
21
- impl http:: HTTPModule for Module {
22
- type MainConf = ( ) ;
23
- type SrvConf = ( ) ;
24
- type LocConf = ModuleConfig ;
22
+ impl http:: HttpModule for Module {
23
+ fn module ( ) -> & ' static ngx_module_t {
24
+ unsafe { & * :: core :: ptr :: addr_of! ( ngx_http_async_module ) }
25
+ }
25
26
26
27
unsafe extern "C" fn postconfiguration ( cf : * mut ngx_conf_t ) -> ngx_int_t {
27
- let cmcf = http:: ngx_http_conf_get_module_main_conf ( cf, & * addr_of ! ( ngx_http_core_module) ) ;
28
+ // SAFETY: this function is called with non-NULL cf always
29
+ let cf = & mut * cf;
30
+ let cmcf = NgxHttpCoreModule :: main_conf_mut ( cf) . expect ( "http core main conf" ) ;
28
31
29
- let h = ngx_array_push ( & mut ( * cmcf) . phases [ ngx_http_phases_NGX_HTTP_ACCESS_PHASE as usize ] . handlers )
32
+ let h = ngx_array_push ( & mut cmcf. phases [ ngx_http_phases_NGX_HTTP_ACCESS_PHASE as usize ] . handlers )
30
33
as * mut ngx_http_handler_pt ;
31
34
if h. is_null ( ) {
32
35
return core:: Status :: NGX_ERROR . into ( ) ;
@@ -42,6 +45,10 @@ struct ModuleConfig {
42
45
enable : bool ,
43
46
}
44
47
48
+ unsafe impl HttpModuleLocationConf for Module {
49
+ type LocationConf = ModuleConfig ;
50
+ }
51
+
45
52
static mut NGX_HTTP_ASYNC_COMMANDS : [ ngx_command_t ; 2 ] = [
46
53
ngx_command_t {
47
54
name : ngx_string ! ( "async" ) ,
@@ -57,10 +64,10 @@ static mut NGX_HTTP_ASYNC_COMMANDS: [ngx_command_t; 2] = [
57
64
static NGX_HTTP_ASYNC_MODULE_CTX : ngx_http_module_t = ngx_http_module_t {
58
65
preconfiguration : Some ( Module :: preconfiguration) ,
59
66
postconfiguration : Some ( Module :: postconfiguration) ,
60
- create_main_conf : Some ( Module :: create_main_conf ) ,
61
- init_main_conf : Some ( Module :: init_main_conf ) ,
62
- create_srv_conf : Some ( Module :: create_srv_conf ) ,
63
- merge_srv_conf : Some ( Module :: merge_srv_conf ) ,
67
+ create_main_conf : None ,
68
+ init_main_conf : None ,
69
+ create_srv_conf : None ,
70
+ merge_srv_conf : None ,
64
71
create_loc_conf : Some ( Module :: create_loc_conf) ,
65
72
merge_loc_conf : Some ( Module :: merge_loc_conf) ,
66
73
} ;
@@ -133,8 +140,7 @@ impl Drop for RequestCTX {
133
140
}
134
141
135
142
http_request_handler ! ( async_access_handler, |request: & mut http:: Request | {
136
- let co = unsafe { request. get_module_loc_conf:: <ModuleConfig >( & * addr_of!( ngx_http_async_module) ) } ;
137
- let co = co. expect( "module config is none" ) ;
143
+ let co = Module :: location_conf( request) . expect( "module config is none" ) ;
138
144
139
145
ngx_log_debug_http!( request, "async module enabled: {}" , co. enable) ;
140
146
0 commit comments