feat: add stream module api#286
Conversation
Stream API was compiled whenever NGINX reported stream support, but nginx-sys only generated stream FFI when its own stream feature was enabled. Add a stream feature to the root crate that propagates to nginx-sys/stream and gate the module with both conditions.
| /// Stream phases in which a module can register handlers. | ||
| #[repr(usize)] | ||
| pub enum StreamPhase { | ||
| /// Post-accept phase |
| ); | ||
| return Err(AllocError); | ||
| } | ||
| // set an H::PHASE phase handler |
| } | ||
| } | ||
|
|
||
| pub use upstream::NgxStreamUpstreamModule; |
There was a problem hiding this comment.
Is it possible to bundle the use statements up at the top?
| /// | ||
| /// The caller has provided a valid non-null pointer to a valid `ngx_stream_session_t` | ||
| /// which shares the same representation as `Request`. | ||
| pub unsafe fn from_ngx_stream_session<'a>(r: *mut ngx_stream_session_t) -> &'a mut Session { |
There was a problem hiding this comment.
You already added this as a From impl so I think this member function is redundant.
| /// | ||
| /// The option wraps an ngx_stream_upstream_t instance, it will be none when the underlying NGINX | ||
| /// request does not have a pointer to a [`ngx_stream_upstream_t`] upstream structure. | ||
| pub fn upstream(&self) -> Option<*mut ngx_stream_upstream_t> { |
There was a problem hiding this comment.
Please return a mut ref instead of a pointer here. This can be implemented as follows:
pub fn upstream(&self) -> Option<&mut ngx_stream_upstream_t> {
self.0.upstream.as_mut()
}This will allow rust callers to use the ref without having to play with as much unsafe code.
| /// Pointer to a [`ngx_connection_t`] client connection object. | ||
| /// | ||
| /// [`ngx_connection_t`]: https://nginx.org/en/docs/dev/development_guide.html#connection | ||
| pub fn connection(&self) -> *mut ngx_connection_t { |
There was a problem hiding this comment.
Again, I would prefer this interface return a mut ref instead. Feel free to .expect(...) it so that you dont need to return an option either.
| /// Pointer to a [`ngx_log_t`]. | ||
| /// | ||
| /// [`ngx_log_t`]: https://nginx.org/en/docs/dev/development_guide.html#logging | ||
| pub fn log(&self) -> *mut ngx_log_t { |
There was a problem hiding this comment.
Same as previous comments about returning a ref.
|
These methods follow the http module's // src/http/request.rs
pub unsafe fn from_ngx_http_request<'a>(r: *mut ngx_http_request_t) -> &'a mut Request
pub fn upstream(&self) -> Option<*mut ngx_http_upstream_t>
pub fn connection(&self) -> *mut ngx_connection_t
pub fn log(&self) -> *mut ngx_log_tReturning |
Proposed changes
Add stream module api support
impl #108
Checklist
Before creating a PR, run through this checklist and mark each as complete.