Skip to content

Commit 5eb1116

Browse files
committed
fix: http::Request's methods return NonNull, not *mut
* the upstream method was already implementing NonNull::new() by using Option to prevent returning a null * the connection and log members are expected throughout nginx to always be nonnull
1 parent 8af61a6 commit 5eb1116

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

src/http/request.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -139,32 +139,27 @@ impl Request {
139139
unsafe { Pool::from_ngx_pool(self.0.pool) }
140140
}
141141

142-
/// Returns the result as an `Option` if it exists, otherwise `None`.
143-
///
144-
/// The option wraps an ngx_http_upstream_t instance, it will be none when the underlying NGINX
145-
/// request does not have a pointer to a [`ngx_http_upstream_t`] upstream structure.
142+
/// Get the request's upstream, if it has one. None indicates the upstream
143+
/// was null.
146144
///
147145
/// [`ngx_http_upstream_t`] is best described in
148146
/// <https://nginx.org/en/docs/dev/development_guide.html#http_load_balancing>
149-
pub fn upstream(&self) -> Option<*mut ngx_http_upstream_t> {
150-
if self.0.upstream.is_null() {
151-
return None;
152-
}
153-
Some(self.0.upstream)
147+
pub fn upstream(&self) -> Option<NonNull<ngx_http_upstream_t>> {
148+
NonNull::new(self.0.upstream)
154149
}
155150

156-
/// Pointer to a [`ngx_connection_t`] client connection object.
151+
/// Get the request's [`ngx_connection_t`] client connection object.
157152
///
158153
/// [`ngx_connection_t`]: https://nginx.org/en/docs/dev/development_guide.html#connection
159-
pub fn connection(&self) -> *mut ngx_connection_t {
160-
self.0.connection
154+
pub fn connection(&self) -> NonNull<ngx_connection_t> {
155+
NonNull::new(self.0.connection).expect("connection is never null")
161156
}
162157

163-
/// Pointer to a [`ngx_log_t`].
158+
/// Get the request's [`ngx_log_t`] log object.
164159
///
165160
/// [`ngx_log_t`]: https://nginx.org/en/docs/dev/development_guide.html#logging
166-
pub fn log(&self) -> *mut ngx_log_t {
167-
unsafe { (*self.connection()).log }
161+
pub fn log(&self) -> NonNull<ngx_log_t> {
162+
NonNull::new(unsafe { self.connection().as_mut() }.log).expect("log is never null")
168163
}
169164

170165
/// Get Module context pointer

0 commit comments

Comments
 (0)