nginx / nginx/ngx-rust

Examples with subrequest

Open
#136 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
915
Forks
96
Avg merge
5d 22h
Merged PRs (30d)
6

Description

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
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the subrequest call and subrequest_callback shown in the issue, then inspect the repository's existing subrequest API and Rust NGINX request bindings. Done means providing an example that sends the original body to a custom server, handles the response, and continues or returns an error for 200 and 403 responses.

Written by the indexing model from the issue text.

Assessment

Tech stack
nginx, rust
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.