Skip to content

Examples with subrequest #136

Description

@azoyan

Is your feature request related to a problem? Please describe.
Show please example of module where we use subrequest with original body to custom own server, handle response and depend on response (403 or 200) return error or continue execution.

I don't know why i have Segfault on my module:

http_request_handler!(wafng_read_post_handler, |request: &mut http::Request| {
    let module = unsafe { addr_of!(NGX_HTTP_WAFNG_MODULE).as_ref().unwrap() };
    let config = request
        .get_module_loc_conf::<ModuleConfig>(module)
        .expect("module config is none");

    if matches!(config.mode, Mode::Off) {
        return Status::NGX_DECLINED;
    }

    let status = request.subrequest("/score", module, subrequest_callback);
}
unsafe extern "C" fn subrequest_callback(
    r: *mut ngx_http_request_t,
    v: *mut c_void,
    i: ngx_int_t,
) -> ngx_int_t {
    let req = unsafe { Request::from_ngx_http_request(r) };
    for (header, value) in req.headers_in_iterator() {
        eprint!("Header = {header}, value = {value}");
    }
    eprintln!("\nRECEIVED SUBREQUEST");
    0
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions