ngx/http/upstream.rs
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///
6/// This macro will define the NGINX callback type:
7/// `typedef ngx_int_t (*ngx_http_upstream_init_peer_pt)(ngx_http_request_t *r, ngx_http_upstream_srv_conf_t *us)`,
8/// we keep this macro name in-sync with its underlying NGINX type, this callback is required to
9/// initialize your peer.
10///
11/// Load Balancing: <https://nginx.org/en/docs/dev/development_guide.html#http_load_balancing>
12#[macro_export]
13macro_rules! http_upstream_init_peer_pt {
14 ( $name: ident, $handler: expr ) => {
15 extern "C" fn $name(
16 r: *mut $crate::ffi::ngx_http_request_t,
17 us: *mut $crate::ffi::ngx_http_upstream_srv_conf_t,
18 ) -> $crate::ffi::ngx_int_t {
19 let status: $crate::core::Status = $handler(
20 unsafe { &mut $crate::http::Request::from_ngx_http_request(r) },
21 us,
22 );
23 status.0
24 }
25 };
26}