Skip to content

How to make the handlers type module like ngx_stab_status #165

Answered by bavshin-f5
u5surf asked this question in Q&A
Discussion options

You must be logged in to vote

With the current git master, the C code for setting the content handler translates to the following Rust:

use ngx::http::HttpModuleLocationConf;

http_request_handler!(example_handler, |_r: &mut ngx::http::Request| {
    ngx::http::HTTPStatus::FORBIDDEN.into()
});

extern "C" fn example_set_handler(
    cf: *mut ngx_conf_t,
    _cmd: *mut ngx_command_t,
    _conf: *mut c_void,
) -> *mut c_char {
    // SAFETY: configuration handlers always receive valid `cf`.
    let cf = unsafe { &mut *cf };

    let clcf = ngx::http::NgxHttpCoreModule::location_conf_mut(cf).expect("core location conf");
    clcf.handler = Some(example_handler);

    ngx::core::NGX_CONF_OK
}

Configuration access traits a…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by u5surf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants