Skip to content

Commit e202d03

Browse files
author
Matthew Yacobucci
committed
Code review notes
Name macro to reflect underlying NGINX type
1 parent d48bcf3 commit e202d03

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/http/request.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,16 @@ impl Request {
117117

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

src/http/upstream.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22
///
33
/// Initializes the upstream 'get', 'free', and 'session' callbacks and gives the module writer an
44
/// 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+
///
511
/// Load Balancing: <https://nginx.org/en/docs/dev/development_guide.html#http_load_balancing>
612
#[macro_export]
7-
macro_rules! http_upstream_peer_init {
13+
macro_rules! http_upstream_init_peer_pt {
814
( $name: ident, $handler: expr ) => {
915
#[no_mangle]
1016
extern "C" fn $name(r: *mut ngx_http_request_t, us: *mut ngx_http_upstream_srv_conf_t) -> ngx_int_t {

0 commit comments

Comments
 (0)