Skip to content

Commit 5b420fc

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

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/http/request.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::core::*;
22
use crate::ffi::*;
3-
use crate::http::status::*;
3+
use crate::http::{status::*, Upstream};
44
use crate::ngx_null_string;
55
use std::fmt;
66
use std::os::raw::c_void;
@@ -117,13 +117,17 @@ 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 Upstream 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
125-
pub fn upstream(&self) -> Option<*mut ngx_http_upstream_t> {
126-
Some(self.0.upstream)
126+
pub fn upstream(&self) -> Option<&mut Upstream> {
127+
if self.0.upstream.is_null() {
128+
return None;
129+
}
130+
Some(unsafe { Upstream::from_ngx_http_upstream(self.0.upstream) })
127131
}
128132

129133
/// Pointer to a [`ngx_connection_t`] client connection object.

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)