File tree 2 files changed +15
-5
lines changed
2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change 1
1
use crate :: core:: * ;
2
2
use crate :: ffi:: * ;
3
- use crate :: http:: status:: * ;
3
+ use crate :: http:: { status:: * , Upstream } ;
4
4
use crate :: ngx_null_string;
5
5
use std:: fmt;
6
6
use std:: os:: raw:: c_void;
@@ -117,13 +117,17 @@ impl Request {
117
117
118
118
/// Returns the result as an `Option` if it exists, otherwise `None`.
119
119
///
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.
121
122
///
122
123
/// [`ngx_http_upstream_t`]: is best described in
123
124
/// https://nginx.org/en/docs/dev/development_guide.html#http_request
124
125
/// 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 ) } )
127
131
}
128
132
129
133
/// Pointer to a [`ngx_connection_t`] client connection object.
Original file line number Diff line number Diff line change 2
2
///
3
3
/// Initializes the upstream 'get', 'free', and 'session' callbacks and gives the module writer an
4
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
+ ///
5
11
/// Load Balancing: <https://nginx.org/en/docs/dev/development_guide.html#http_load_balancing>
6
12
#[ macro_export]
7
- macro_rules! http_upstream_peer_init {
13
+ macro_rules! http_upstream_init_peer_pt {
8
14
( $name: ident, $handler: expr ) => {
9
15
#[ no_mangle]
10
16
extern "C" fn $name( r: * mut ngx_http_request_t, us: * mut ngx_http_upstream_srv_conf_t) -> ngx_int_t {
You can’t perform that action at this time.
0 commit comments