-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: (1 of 2) Supporting changes for upstream example module. (#36)
* feat: Supporting changes for upstream example module. - functions to get mut and const module context from the ngx_http_upstream_srv_conf_t - Request from trait - Request upstream getter - Request peer init macro --------- Co-authored-by: Matthew Yacobucci <[email protected]>
- Loading branch information
1 parent
7972ae7
commit 8b3a119
Showing
4 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/// Define a static upstream peer initializer | ||
/// | ||
/// Initializes the upstream 'get', 'free', and 'session' callbacks and gives the module writer an | ||
/// opportunity to set custom data. | ||
/// | ||
/// This macro will define the NGINX callback type: | ||
/// `typedef ngx_int_t (*ngx_http_upstream_init_peer_pt)(ngx_http_request_t *r, ngx_http_upstream_srv_conf_t *us)`, | ||
/// we keep this macro name in-sync with its underlying NGINX type, this callback is required to | ||
/// initialize your peer. | ||
/// | ||
/// Load Balancing: <https://nginx.org/en/docs/dev/development_guide.html#http_load_balancing> | ||
#[macro_export] | ||
macro_rules! http_upstream_init_peer_pt { | ||
( $name: ident, $handler: expr ) => { | ||
#[no_mangle] | ||
extern "C" fn $name(r: *mut ngx_http_request_t, us: *mut ngx_http_upstream_srv_conf_t) -> ngx_int_t { | ||
let status: Status = $handler(unsafe { &mut Request::from_ngx_http_request(r) }, us); | ||
status.0 | ||
} | ||
}; | ||
} |