Skip to content

Simple subrequest support#254

Open
ensh63 wants to merge 2 commits intonginx:mainfrom
ensh63:shirykalov/subrequest
Open

Simple subrequest support#254
ensh63 wants to merge 2 commits intonginx:mainfrom
ensh63:shirykalov/subrequest

Conversation

@ensh63
Copy link
Copy Markdown
Contributor

@ensh63 ensh63 commented Feb 13, 2026

  • Typed storage in Pool with cleanup support;
  • Request context support for HTTP phase modules;
  • Simple version of HTTP subrequest support:
    • subrequest builder;
    • subrequest handler with support of user-supplied function or closure;
    • example of use;
  • refactoring for Status conversions

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces subrequest support for nginx Rust bindings along with typed storage in Pool and request context management. The changes enable HTTP modules to create and manage subrequests with user-defined handlers, while also adding infrastructure for request-specific context data and improved pool memory management.

Changes:

  • Adds HTTP subrequest builder API with support for in-memory, waited, and background subrequests
  • Implements RequestContext trait for type-safe, module-scoped request context management with automatic cleanup
  • Enhances Pool with typed storage methods (allocate, get_or_add_unique, remove) using cleanup handlers for RAII

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/http/subrequest.rs New subrequest builder and handler implementation with memory-pool-based allocation
src/http/request_context.rs RequestContext trait for managing typed request-specific data
src/http/request.rs Added get_main/get_main_mut, get_status methods and Result<T,E> IntoHandlerStatus impl
src/http/status.rs Refactored to use TryFrom trait instead of custom from_* methods, simplified error type
src/http/mod.rs Exports new subrequest and request_context modules
src/core/pool.rs Enhanced with typed allocation, unique value storage, and cleanup management
src/log.rs Updated macro to use safe log() method instead of unsafe pointer access
examples/subrequest.rs Example demonstrating subrequest usage with context management
examples/Cargo.toml Added subrequest example configuration

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/http/subrequest.rs Outdated
Comment thread src/http/request.rs Outdated
Comment thread src/http/subrequest.rs
@ensh63 ensh63 force-pushed the shirykalov/subrequest branch 8 times, most recently from acf1162 to e63cec9 Compare February 17, 2026 23:30
@ensh63 ensh63 requested a review from Copilot February 18, 2026 17:21
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 6 comments.

Comments suppressed due to low confidence (1)

src/http/status.rs:84

  • The refactoring removes the public methods HTTPStatus::from_u16 and HTTPStatus::from_bytes and replaces them with TryFrom trait implementations. This is a breaking API change that could affect existing users of the library. Consider either keeping the old methods as wrappers around the new TryFrom implementations for backward compatibility, or documenting this breaking change in the PR description and release notes.
impl TryFrom<usize> for HTTPStatus {
    type Error = InvalidHTTPStatusCode;

    #[inline]
    fn try_from(value: usize) -> Result<Self, Self::Error> {
        if !(100..600).contains(&value) {
            return Err(InvalidHTTPStatusCode);
        }
        Ok(HTTPStatus(value))
    }
}

impl TryFrom<isize> for HTTPStatus {
    type Error = InvalidHTTPStatusCode;

    #[inline]
    fn try_from(value: isize) -> Result<Self, Self::Error> {
        let value: usize = value.try_into().map_err(|_| InvalidHTTPStatusCode)?;
        Self::try_from(value)
    }
}

impl TryFrom<&[u8]> for HTTPStatus {
    type Error = InvalidHTTPStatusCode;

    fn try_from(value: &[u8]) -> Result<Self, Self::Error> {
        if value.len() != 3 {
            return Err(InvalidHTTPStatusCode);
        }

        let a = value[0].wrapping_sub(b'0') as u16;
        let b = value[1].wrapping_sub(b'0') as u16;
        let c = value[2].wrapping_sub(b'0') as u16;

        if a == 0 || a > 5 || b > 9 || c > 9 {
            return Err(InvalidHTTPStatusCode);
        }

        let status = (a * 100) + (b * 10) + c;
        Ok(HTTPStatus(status.into()))
    }
}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/http/subrequest.rs Outdated
Comment thread examples/subrequest.rs Outdated
Comment thread examples/subrequest.rs Outdated
Comment thread src/core/pool.rs Outdated
Comment thread src/http/status.rs
Comment thread src/http/request_context.rs Outdated
@ensh63 ensh63 force-pushed the shirykalov/subrequest branch from e63cec9 to e2094f7 Compare February 18, 2026 19:18
@ensh63 ensh63 changed the title Draft: simple subrequest support Simple subrequest support Feb 18, 2026
@ensh63 ensh63 force-pushed the shirykalov/subrequest branch 12 times, most recently from cb8d7ac to 961b0c5 Compare February 24, 2026 23:53
@ensh63 ensh63 force-pushed the shirykalov/subrequest branch 3 times, most recently from 4a44149 to a626dbf Compare March 26, 2026 18:25
@ensh63 ensh63 force-pushed the shirykalov/subrequest branch 4 times, most recently from 856e191 to 98189ce Compare April 3, 2026 20:36
Comment thread src/core/pool.rs Outdated
Comment thread src/core/pool.rs
Comment thread src/core/pool.rs Outdated
Comment thread src/core/pool.rs Outdated
Comment thread src/core/pool.rs Outdated
Comment thread src/core/pool.rs Outdated
Comment thread src/core/pool.rs Outdated
Comment thread src/core/pool.rs Outdated
Comment thread src/core/pool.rs Outdated
Comment thread src/core/pool.rs Outdated
@ensh63 ensh63 force-pushed the shirykalov/subrequest branch from 98189ce to cdaff82 Compare April 4, 2026 00:36
Comment thread src/core/pool.rs Outdated
Comment thread src/core/pool.rs Outdated
Comment thread src/http/subrequest.rs Outdated
Comment thread src/http/request.rs
Comment thread src/http/request.rs Outdated
@ensh63 ensh63 force-pushed the shirykalov/subrequest branch 2 times, most recently from 7ad251c to 4764b6b Compare April 6, 2026 20:36
Comment thread src/http/subrequest.rs Outdated
Comment thread src/http/subrequest.rs
Comment thread src/http/mod.rs Outdated
Comment thread src/http/subrequest.rs Outdated
Comment thread src/http/subrequest.rs Outdated
@ensh63 ensh63 force-pushed the shirykalov/subrequest branch 7 times, most recently from f0ae054 to 1c81c70 Compare April 10, 2026 16:14
@ensh63 ensh63 force-pushed the shirykalov/subrequest branch from 1c81c70 to 0cc77a4 Compare April 14, 2026 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants