feat: add core main-conf access#272
Conversation
|
This is a really useful addition. But I'd like to suggest to make one step further and implement configuration trait for arbitrary core module similar to |
|
Sure thing @ensh63 , I'll follow up next week with CoreModuleConf |
|
Updated with CoreModuleMainConf, made NgxCoreModule a concrete implementation of it. Cleaned out the lingering public accessors from testing. |
| } | ||
|
|
||
| /// Auxiliary structure to access `ngx_core_module` configuration. | ||
| pub struct NgxCoreModule; |
There was a problem hiding this comment.
I think we may expect a special trait for core module, similar to HttpModule trait. To make this PR minimal, I'd suggest to include only module() method to it for now. In future this will allow to add all other necessary components to this trait.
There was a problem hiding this comment.
Thanks for your patience and guidance on this one, I'm still wrapping my head around all this but I believe the recent change achieves what you are asking.
Add core main-conf wrapper for accessing top-level core main configuration in ngx-rust. This introduces: - CoreModuleConfExt for ngx_conf_t and ngx_cycle_t - core_main_conf / core_main_conf_mut typed helpers - NgxCoreModule convenience accessors for ngx_core_conf_t The new API mirrors the existing HTTP config helper style while centralizing the unsafe conf_ctx slot traversal in one place. Why: Modules that need core process configuration currently have to manually walk cycle->conf_ctx, index with ngx_core_module.index, and cast to ngx_core_conf_t. That is repetitive, easy to get wrong, and noisy in reviews. (cherry picked from commit 56f27a4)
Add core main-conf wrapper for accessing top-level core main configuration in ngx-rust. This introduces: - CoreModuleConfExt for ngx_conf_t and ngx_cycle_t - core_main_conf / core_main_conf_mut typed helpers - NgxCoreModule convenience accessors for ngx_core_conf_t The new API mirrors the existing HTTP config helper style while centralizing the unsafe conf_ctx slot traversal in one place. Why: Modules that need core process configuration currently have to manually walk cycle->conf_ctx, index with ngx_core_module.index, and cast to ngx_core_conf_t. That is repetitive, easy to get wrong, and noisy in reviews. (cherry picked from commit 56f27a4)
Add safe accessors for request struct fields that previously
required raw-pointer deref:
- `Request::upstream_states() -> &[UpstreamState]` walks each
upstream attempt (one per peer for `proxy_next_upstream`
retries) via a `#[repr(transparent)]` wrapper exposing
`peer`, `status`, `response_time`, `connect_time`,
`header_time`, `queue_time`, `bytes_sent`, `bytes_received`,
`response_length`.
- `Request::start_sec()`, `start_msec()`, `request_length()`,
`bytes_sent()` for the request-level timing/byte fields.
`Request::upstream()` (the raw-pointer accessor) is left untouched
to preserve compatibility.
Unit tests follow the `MaybeUninit::zeroed` pattern from nginx#272.
Add safe accessors for request struct fields that previously
required raw-pointer deref:
- `Request::upstream_states() -> &[UpstreamState]` walks each
upstream attempt (one per peer for `proxy_next_upstream`
retries) via a `#[repr(transparent)]` wrapper exposing
`peer`, `status`, `response_time`, `connect_time`,
`header_time`, `queue_time`, `bytes_sent`, `bytes_received`,
`response_length`.
- `Request::start_sec()`, `start_msec()`, `request_length()`,
`bytes_sent()` for the request-level timing/byte fields.
`Request::upstream()` (the raw-pointer accessor) is left untouched
to preserve compatibility.
Unit tests follow the `MaybeUninit::zeroed` pattern from nginx#272.
Signed-off-by: Y.Horie <u5.horie@gmail.com>
Add core main-conf wrapper for accessing top-level core main
configuration in ngx-rust.
This introduces:
The new API mirrors the existing HTTP config helper style while
centralizing the unsafe conf_ctx slot traversal in one place.
Why:
Modules that need core process configuration currently have to manually
walk cycle->conf_ctx, index with ngx_core_module.index, and cast to
ngx_core_conf_t. That is repetitive, easy to get wrong, and noisy in
reviews.
The immediate use case is the nginx-wasm issue where module
code needs access to core config such as the env state.
Ref: https://github.com/nginx/nginx-wasm/issues/37