File tree 4 files changed +69
-0
lines changed
4 files changed +69
-0
lines changed Original file line number Diff line number Diff line change @@ -31,3 +31,33 @@ pub unsafe fn ngx_http_conf_get_module_loc_conf(
31
31
let http_conf_ctx = ( * cf) . ctx as * mut ngx_http_conf_ctx_t ;
32
32
* ( * http_conf_ctx) . loc_conf . add ( module. ctx_index ) as * mut ngx_http_core_loc_conf_t
33
33
}
34
+
35
+ /// # Safety
36
+ ///
37
+ /// The caller has provided a value `ngx_http_upstream_srv_conf_t. If the `us` argument is null, a
38
+ /// None Option is returned; however, if the `us` internal fields are invalid or the module index
39
+ /// is out of bounds failures may still occur.
40
+ pub unsafe fn ngx_http_conf_upstream_srv_conf_immutable < T > (
41
+ us : * const ngx_http_upstream_srv_conf_t ,
42
+ module : & ngx_module_t ,
43
+ ) -> Option < * const T > {
44
+ if us. is_null ( ) {
45
+ return None ;
46
+ }
47
+ Some ( * ( * us) . srv_conf . add ( module. ctx_index ) as * const T )
48
+ }
49
+
50
+ /// # Safety
51
+ ///
52
+ /// The caller has provided a value `ngx_http_upstream_srv_conf_t. If the `us` argument is null, a
53
+ /// None Option is returned; however, if the `us` internal fields are invalid or the module index
54
+ /// is out of bounds failures may still occur.
55
+ pub unsafe fn ngx_http_conf_upstream_srv_conf_mutable < T > (
56
+ us : * const ngx_http_upstream_srv_conf_t ,
57
+ module : & ngx_module_t ,
58
+ ) -> Option < * mut T > {
59
+ if us. is_null ( ) {
60
+ return None ;
61
+ }
62
+ Some ( * ( * us) . srv_conf . add ( module. ctx_index ) as * mut T )
63
+ }
Original file line number Diff line number Diff line change @@ -2,8 +2,10 @@ mod conf;
2
2
mod module;
3
3
mod request;
4
4
mod status;
5
+ mod upstream;
5
6
6
7
pub use conf:: * ;
7
8
pub use module:: * ;
8
9
pub use request:: * ;
9
10
pub use status:: * ;
11
+ pub use upstream:: * ;
Original file line number Diff line number Diff line change @@ -79,6 +79,17 @@ macro_rules! http_variable_get {
79
79
#[ repr( transparent) ]
80
80
pub struct Request ( ngx_http_request_t ) ;
81
81
82
+ impl < ' a > From < & ' a Request > for * const ngx_http_request_t {
83
+ fn from ( request : & ' a Request ) -> Self {
84
+ & request. 0 as * const _
85
+ }
86
+ }
87
+ impl < ' a > From < & ' a mut Request > for * mut ngx_http_request_t {
88
+ fn from ( request : & ' a mut Request ) -> Self {
89
+ & request. 0 as * const _ as * mut _
90
+ }
91
+ }
92
+
82
93
impl Request {
83
94
/// Create a [`Request`] from an [`ngx_http_request_t`].
84
95
///
@@ -104,6 +115,17 @@ impl Request {
104
115
unsafe { Pool :: from_ngx_pool ( self . 0 . pool ) }
105
116
}
106
117
118
+ /// Returns the result as an `Option` if it exists, otherwise `None`.
119
+ ///
120
+ /// The option wraps a pointer to a [`ngx_http_upstream_t`] upstream server object.
121
+ ///
122
+ /// [`ngx_http_upstream_t`]: is best described in
123
+ /// https://nginx.org/en/docs/dev/development_guide.html#http_request
124
+ /// https://nginx.org/en/docs/dev/development_guide.html#http_load_balancing
125
+ pub fn upstream ( & self ) -> Option < * mut ngx_http_upstream_t > {
126
+ Some ( self . 0 . upstream )
127
+ }
128
+
107
129
/// Pointer to a [`ngx_connection_t`] client connection object.
108
130
///
109
131
/// [`ngx_connection_t`]: https://nginx.org/en/docs/dev/development_guide.html#connection
Original file line number Diff line number Diff line change
1
+ /// Define a static upstream peer initializer
2
+ ///
3
+ /// Initializes the upstream 'get', 'free', and 'session' callbacks and gives the module writer an
4
+ /// opportunity to set custom data.
5
+ /// Load Balancing: <https://nginx.org/en/docs/dev/development_guide.html#http_load_balancing>
6
+ #[ macro_export]
7
+ macro_rules! http_upstream_peer_init {
8
+ ( $name: ident, $handler: expr ) => {
9
+ #[ no_mangle]
10
+ extern "C" fn $name( r: * mut ngx_http_request_t, us: * mut ngx_http_upstream_srv_conf_t) -> ngx_int_t {
11
+ let status: Status = $handler( unsafe { & mut Request :: from_ngx_http_request( r) } , us) ;
12
+ status. 0
13
+ }
14
+ } ;
15
+ }
You can’t perform that action at this time.
0 commit comments