Skip to content

Commit

Permalink
Code review notes
Browse files Browse the repository at this point in the history
Name macro to reflect underlying NGINX type
  • Loading branch information
Matthew Yacobucci committed Aug 31, 2023
1 parent d48bcf3 commit e202d03
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/http/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,16 @@ impl Request {

/// Returns the result as an `Option` if it exists, otherwise `None`.
///
/// The option wraps a pointer to a [`ngx_http_upstream_t`] upstream server object.
/// The option wraps an ngx_http_upstream_t instance, it will be none when the underlying NGINX request
/// does not have a pointer to a [`ngx_http_upstream_t`] upstream structure.
///
/// [`ngx_http_upstream_t`]: is best described in
/// https://nginx.org/en/docs/dev/development_guide.html#http_request
/// https://nginx.org/en/docs/dev/development_guide.html#http_load_balancing
pub fn upstream(&self) -> Option<*mut ngx_http_upstream_t> {
if self.0.upstream.is_null() {
return None;
}
Some(self.0.upstream)
}

Expand Down
8 changes: 7 additions & 1 deletion src/http/upstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
///
/// 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_peer_init {
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 {
Expand Down

0 comments on commit e202d03

Please sign in to comment.