Skip to content

Support experimental HTTP middleware in HttpServerRunner constructor - #311

Merged
clue merged 2 commits into
clue:mainfrom
clue-labs:http-middleware
Sep 23, 2026
Merged

clue merged 2 commits into
clue:mainfrom
clue-labs:http-middleware

Conversation

@clue

@clue clue commented Sep 23, 2026 •

Copy link
Copy Markdown
Owner

This changeset adds experimental support for passing HTTP middleware to the HttpServerRunner constructor. The goal is to raise the built-in web server's 64 KiB request body limit, but this can also be used to preprocess or filter requests before they reach X:

$container = new FrameworkX\Container([
    FrameworkX\Runner\HttpServerRunner::class => function (?string $X_LISTEN = null) {
        return new FrameworkX\Runner\HttpServerRunner(
            new FrameworkX\Io\LogStreamHandler('php://output'),
            $X_LISTEN,
            [
                new React\Http\Middleware\StreamingRequestMiddleware(),
                new React\Http\Middleware\LimitConcurrentRequestsMiddleware(10),
                new React\Http\Middleware\RequestBodyBufferMiddleware('8M'),
                new React\Http\Middleware\RequestBodyParserMiddleware('2M')
            ]
        );
    }
]);

$app = new FrameworkX\App($container);

Note that this is an experimental feature and the API may be subject to change in future releases. Once X handles larger request bodies on its own, this may no longer be needed, but for now this avoids having to patch X. The first commit also makes sure a failure to create the HTTP server no longer leaves the listen address bound.

Without any middleware given, the HTTP server behaves exactly as before, so this should be safe to apply.

Builds on top of #294, #295, #292, #224, #237, #117, #156, #13 and others
Refs #234, #293, #196, #193 and #190

@clue clue added this to the v0.18.0 milestone Sep 23, 2026
@clue clue added the new feature New feature or request label Sep 23, 2026
@clue
clue requested a lite review from Copilot September 23, 2026 21:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

No blocking issues were identified; one minor documentation clarification remains.

Review effort: Lite
Findings: None

What changed in this PR

Adds experimental HTTP middleware support to HttpServerRunner, with safer server initialization and configurable request-body handling.

Changes:

  • Adds middleware validation and execution.
  • Prevents binding when server creation fails.
  • Adds tests and documentation for request-body limits.
File Summary
tests/​Runner/​HttpServerRunnerTest.php Tests middleware, validation, buffering, and cleanup.
src/​Runner/​HttpServerRunner.php Adds middleware support and safer initialization.
docs/​best-practices/​deployment.md Documents middleware configuration and request limits; clarify the stated 100 MiB memory bound.
docs/​api/​request.md Documents default request-body limits.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@clue
clue merged commit b3a5508 into clue:main Sep 23, 2026
75 checks passed
@clue
clue deleted the http-middleware branch September 23, 2026 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants