From 71a1aab3f17a441bf353e57e3294b14da53360de Mon Sep 17 00:00:00 2001 From: stefansorge <3419073+sorge-it@users.noreply.github.com> Date: Sat, 21 Nov 2026 18:05:20 +0100 Subject: [PATCH] chore: release 1.1.0 The follow-ups of the second rating of 1.0.0 and the review by eight roles: the loopback check before the bind, clearer errors, the attestation in every Docker job, the community files in .github. --- .github/CONTRIBUTING.md | 21 ++--- .github/pull_request_template.md | 4 +- CHANGELOG.md | 33 +++++--- README.md | 131 ++++++++++++++++--------------- composer.json | 2 +- tests/Scope/out.php | 2 +- 6 files changed, 104 insertions(+), 89 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 330b58c..66bf32f 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -9,8 +9,7 @@ Everyone who takes part follows the ## Setup You need Composer, PHP 8.4 or a later 8.x with the `sockets`, `pdo_sqlite` and `curl` extensions, -and pcov or Xdebug for line coverage. The two browser examples also need Chrome; see the `Example` -suite below. +and pcov or Xdebug for line coverage. The two browser tests also need Chrome; see [Tests](#tests). ```sh composer install @@ -39,8 +38,9 @@ composer test # Pint and Rector dry runs, PHPStan, 100% type cove Before you open a pull request: ```sh -composer test:coverage # 100% line coverage, needs pcov or Xdebug composer lint # Rector, then Pint +composer test # the dry runs of both, PHPStan, 100% type coverage, every suite +composer test:coverage # 100% line coverage, needs pcov or Xdebug composer validate --strict # composer.json against its schema composer audit --locked # advisories for the locked packages, needs the network ``` @@ -50,7 +50,7 @@ PHPStan, Rector and the type coverage read `src` and `tests`; Pint reads the who The code must run on PHP 8.4 and 8.5, on macOS, and on Linux with glibc and with musl. The Docker jobs in CI run the suites as a non-root user, so that the file-mode tests run. To run such a job locally, use a clean clone, because the command copies the whole directory. Use `debian` -or `alpine` as the image name: +or `alpine` as the directory in `.github/docker/`: ```sh docker build --quiet --tag tests .github/docker/debian @@ -81,9 +81,10 @@ docker run --rm --volume "$PWD:/src:ro" --workdir /src actionlint -no-color - Where Go `net/http` decides the result, the test is a probe in `tests/Fixtures/go-net-http/cases.json`, with the fields `group`, `name`, `source: "probe"`, - `rule` (Go's file and function) and `request`, and the limits `maxHeaderBytes` or - `maxHeaderValueCount` where needed. Then run `composer go:extract`. The `GoNetHttp` suite sends - the probe to Go for the parser and to FrankenPHP for the response, and compares the bytes. + `rule` (Go's file and function) and `request`, and the limits `maxHeaderBytes`, + `maxHeaderValueCount` or `maxBody` where needed. Then run `composer go:extract`. The `GoNetHttp` + suite sends the probe to Go for the parser and to FrankenPHP for the response, and compares the + bytes. - Where Caddy decides, the probe goes into `tests/Fixtures/caddy/cases.json` in the same form, with Caddy's file and function as `rule`, and the `FrankenPhp` suite compares it against FrankenPHP. - No test spells out a FrankenPHP response as a literal. Where the handler must be PHP, compare @@ -139,12 +140,12 @@ composer frankenphp:lock # new FrankenPHP versions into release.lock, needs gh - The newest FrankenPHP is its newest release, not its newest tag: upstream tags a version and publishes the release hours later. - `check:frankenphp` downloads the newest FrankenPHP binary into `.frankenphp/newest` and runs it. - When it finds new versions, run `composer frankenphp:lock`. It writes the versions of the newest + When it finds new versions, run `composer frankenphp:lock`. `frankenphp:lock` writes the versions of the newest binary into `release.lock` after `gh attestation verify` shows that FrankenPHP's workflow built each binary. If the versions are unchanged, it writes nothing. - Then update each lock file that the `pins` group test in `tests/FrankenPhp/FrankenPhpTest.php` - reads, each version that it names, and the tags in `tests/Fixtures/README.md`. The README names - no pinned version. + reads, each version that it names, and the tags in `tests/Fixtures/README.md`. The root README + names no pinned version. ## Scope diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 42955af..8452a33 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,6 +1,6 @@ - + -**What goes wrong, or what the feature does:** +**What went wrong and what you expected, or what the feature does; with a fix, why it works:** **The row of Scope in the README that it touches, and the layer that decides it:** diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f5a4a0..fe57bc5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,26 +6,32 @@ All notable changes to this package are in this file. The format follows ## [Unreleased] -### Changed +## [1.1.0] - 2026-11-21 -- Four more messages name the way out: `ClosedWithErrors` names a request cut by `close()` and the - `onError` that fails the test at the error; a chunk that is not a string names `json_encode()`; a handler that returns `null` - is told to return a `Response` from every path; a host that is not loopback names where the - browser runs. +### Changed +- For a name such as `localhost`, the server listens on the address that its loopback check + resolved the name to. When the port is taken there, `new Server()` throws `ListenFailed` instead + of trying the next address. +- For a `$host` with a port or a scheme, such as `127.0.0.1:8080`, `new Server()` throws + `ListenFailed` at once and names `$port`, instead of passing on an error of the resolver. For a + host that cannot be bound, the message of `ListenFailed` contains "could not bind". +- Error messages name the way out: + - a handler that returns `null`: return a `Response` from every path; + - a handler that returns another value: the fully qualified `Response` class and the README + section "Works with Symfony, Laravel and PSR-15"; + - `ClosedWithErrors`: fix the handler or let each request finish before `close()`, and the + `onError` that fails the test at the error; + - a chunk of a streamed body that is not a string: `json_encode()` for JSON; + - a host that is not loopback: run the browser on the same host or in the same container. - `SECURITY.md` moved to `.github/` and is no longer in the package. The security link in `composer.json` points to the security policy on GitHub. -- Three messages name the fix. A handler that gives another type than `Response` names the full - class and the section "Works with Symfony, Laravel and PSR-15". `ClosedWithErrors` says to fix - the handler first. A `$host` with a port or a scheme, such as `127.0.0.1:8080`, throws - `ListenFailed` at once and names `$port`, instead of an error of the resolver. ### Fixed - `new Server()` refuses a host that resolves to an address that is not loopback, such as - `0.0.0.0` or `0`, before it listens. Until now it listened on the address for a moment and then - refused it. A host that cannot be bound now throws `ListenFailed` with "could not bind". A name - such as `localhost` now listens only on the first address it resolves to. + `0.0.0.0` or `0`, before it listens. Previously, it listened on the address for a moment and + then refused it. ## [1.0.0] - 2026-11-20 @@ -38,5 +44,6 @@ response with the FrankenPHP binary, in the form that Chrome receives, and the p `net/http`. The README states the scope and each deliberate difference. The 0.x releases were private. -[Unreleased]: https://github.com/sorge-it/http-server/compare/v1.0.0...HEAD +[Unreleased]: https://github.com/sorge-it/http-server/compare/v1.1.0...HEAD +[1.1.0]: https://github.com/sorge-it/http-server/compare/v1.0.0...v1.1.0 [1.0.0]: https://github.com/sorge-it/http-server/releases/tag/v1.0.0 diff --git a/README.md b/README.md index ded0501..5dab5c4 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# HttpServer: an in-process HTTP server for Pest and PHPUnit browser tests, built for coding agents +# HttpServer: an in-process HTTP/1.1 server for Pest and PHPUnit browser tests, built for coding agents [![Tests](https://github.com/sorge-it/http-server/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/sorge-it/http-server/actions/workflows/tests.yml?query=branch%3Amain) [![Latest FrankenPHP](https://github.com/sorge-it/http-server/actions/workflows/frankenphp.yml/badge.svg?branch=main)](https://github.com/sorge-it/http-server/actions/workflows/frankenphp.yml?query=branch%3Amain) @@ -15,7 +15,7 @@ for coding agents. It serves the page from the test process, so the page sees th ![A test holds a database transaction with the user Ada. Headless Chromium loads the users page: served by php -S in a second process, it shows no users; served by HttpServer in the test process, it shows Ada](https://raw.githubusercontent.com/sorge-it/http-server/main/demo/output/demo.gif) -The demo in [`demo/`](demo) holds a transaction with the user Ada, as Laravel's `RefreshDatabase` +The demo in [`demo/`](https://github.com/sorge-it/http-server/tree/main/demo) holds a transaction with the user Ada, as Laravel's `RefreshDatabase` does, while headless Chromium loads a page that lists the users. Served by `php -S`, the page shows no users; served by HttpServer, it shows Ada. @@ -23,12 +23,13 @@ no users; served by HttpServer, it shows Ada. [`sorge-it/pest-plugin-browser-cdp`](https://github.com/sorge-it/pest-plugin-browser-cdp) serves your app with it, so `RefreshDatabase`, `actingAs()` and fakes such as `Mail::fake()` reach the page. -- **Already using `pestphp/pest-plugin-browser`?** There, the page sees the test's state too. +- **Already using `pestphp/pest-plugin-browser`?** With it, the page sees the test's state too. [`pest-plugin-browser-cdp`](https://github.com/sorge-it/pest-plugin-browser-cdp) runs your tests - on HttpServer instead, without Node and Playwright. For the methods that its README marks `built`, - it is [faster and uses half the - memory](https://github.com/sorge-it/pest-plugin-browser-cdp#measurements). -- **Testing another framework or plain PHP, or building a browser driver or test harness?** Read on: + on HttpServer instead, without Node and Playwright, if they use only the methods that its README + marks `built`. In its demo, it ran faster than `pest-plugin-browser` and used half the memory + ([measurements](https://github.com/sorge-it/pest-plugin-browser-cdp#measurements)). +- **Testing Laravel with PHPUnit, another framework or plain PHP, or building a browser driver or + test harness?** Read on: the handler is a callable that turns a `Request` into a `Response`. [Works with Symfony, Laravel and PSR-15](#works-with-symfony-laravel-and-psr-15) has a handler for each. @@ -65,8 +66,7 @@ requires 100% line and type coverage, and the weekly mutation tests require a sc 17. [License](#license) 18. [About the author](#about-the-author) -Sections 1 to 11 are for users. Sections 12 to 14 are the reference: read them when you need a -detail. +Sections 1 to 11 are for users. Sections 12 to 14 are for looking up the details. ## Why RefreshDatabase and actingAs() don't reach the page @@ -97,17 +97,17 @@ HttpServer makes both safe: [Compatibility](#compatibility-with-frankenphp). - **The test shows the error.** With `onError: static fn (Throwable $e): never => throw $e`, a handler exception fails the test with its class, message, file and line - ([test](tests/Handler/HandlerTest.php)). Laravel and Symfony catch the exceptions of their app + ([test](https://github.com/sorge-it/http-server/blob/main/tests/Handler/HandlerTest.php)). Laravel and Symfony catch the exceptions of their app first; see [Works with](#works-with-symfony-laravel-and-psr-15). Under `php -S` without a php.ini, the exception stays in the server process: the test gets status 200 and an HTML page with the fatal error (measured by hand on 2026-11-16; no suite repeats it). - **Debug output is in the run.** `echo` and `var_dump()` in the app print into the test's output, as in a unit test, and `error_log()` writes where the test process logs - ([test](tests/BeyondGo/SharedStateTest.php)). The response body stays as the handler returned it. + ([test](https://github.com/sorge-it/http-server/blob/main/tests/BeyondGo/SharedStateTest.php)). The response body stays as the handler returned it. - **No server process.** There is no server process to start, to wait for or to kill, and none is left after a failed run. - **The test sees what the page did.** After a request, the test reads the same database - transaction and the same fakes as the app ([test](works-with/laravel/WorksWithTest.php)). + transaction and the same fakes as the app ([test](https://github.com/sorge-it/http-server/blob/main/works-with/laravel/WorksWithTest.php)). ## Installation @@ -115,16 +115,16 @@ HttpServer makes both safe: composer require --dev sorge-it/http-server ``` -It requires PHP 8.4 or a later 8.x, the extension `ext-filter`, which PHP builds by default, and -no other packages. It runs on Linux and macOS: CI runs the suites on Ubuntu, Debian, Alpine and +It requires PHP 8.4 or a later 8.x, the `filter` extension, which PHP enables by default, and no +other packages. It runs on Linux and macOS: CI runs the suites on Ubuntu, Debian, Alpine and macOS. Windows is not supported, because no CI job runs there. Versions follow [Semantic Versioning](https://semver.org): the classes and the interface marked `@api` are the public API, and [CHANGELOG.md](CHANGELOG.md) lists each change. ## Quick start -Save this as `serve.php` in the project root, run `php serve.php`, and open the URL it prints -within 60 seconds: +Save this as `serve.php` in the project root, run `php serve.php`, and within 60 seconds open the +URL that it prints: ```php close(); A handler is a plain callable, so a unit test calls it without a server, a socket or a browser. `StringBody` gives the request a body; a `Request` without one has an empty body. The test checks -the `Response` by its public properties: +the `Response` by its public properties. Save it as `tests/UnitTest.php`: ```php withoutExceptionHandling([NotFoundHttpException::class])` turns this off: each exception - from the app reaches `onError`, except a class in the list. So a missing route, such as + `$this->withoutExceptionHandling([NotFoundHttpException::class])` turns this off: every exception + from the app reaches `onError`, unless its class is in the list. So a missing route, such as `/favicon.ico`, still gets its 404. A form that fails validation throws a `ValidationException`: add its class to the list when the test expects the framework's response. In a Symfony test, `catch: false` in the call of `handle()` in `symfonyHandler()` passes each exception from the app - to `onError`, also the `NotFoundHttpException` of `/favicon.ico`. + to `onError`, including the `NotFoundHttpException` of `/favicon.ico`. -The weekly CI job [`works-with`](.github/workflows/works-with.yml) runs each file with the newest +The weekly CI job [`works-with`](https://github.com/sorge-it/http-server/blob/main/.github/workflows/works-with.yml) runs each file with the newest release of its framework. A client in a second process posts a form with a query, a cookie and a header. The app answers with status 201, a header and two cookies; Symfony and Laravel answer with a `StreamedResponse`. @@ -659,7 +662,8 @@ the test process that ticks the server while it waits. Do not use it for: -- Laravel Dusk, Symfony Panther or any other WebDriver client: they block the test process; +- Laravel Dusk, Symfony Panther or any other WebDriver client, and a Chrome DevTools Protocol client + that waits synchronously, such as `chrome-php/chrome`: they block the test process; - a mock server for your own HTTP client, such as Guzzle or Symfony HttpClient: they block the process while the server needs a tick. Use Guzzle's `MockHandler`, Laravel's `Http::fake()` or Symfony's `MockHttpClient` instead; @@ -675,11 +679,11 @@ Do not use it for: | | `php -S`, `php artisan serve` | `amphp/http-server` 3.4.9, used by `pestphp/pest-plugin-browser` 5.2.0 | `react/http` 1.12.0 | `sorge-it/http-server` | Source | |---|---|---|---|---|---| | Runs in | a second process | the test process | the test process | the test process | [PHP manual](https://www.php.net/manual/en/features.commandline.webserver.php), [ServeCommand.php of Laravel 13.43.0](https://github.com/laravel/framework/blob/v13.43.0/src/Illuminate/Foundation/Console/ServeCommand.php), [LaravelHttpServer.php of pest-plugin-browser 5.2.0](https://github.com/pestphp/pest-plugin-browser/blob/v5.2.0/src/Drivers/LaravelHttpServer.php), [README of react/http 1.12.0](https://github.com/reactphp/http/blob/v1.12.0/README.md#server-usage) | -| The page can see the test's transaction, authenticated user and fakes | no | yes | yes | yes | the [demo](demo) for `php -S`; for the others, the handler runs in the test process | +| The page can see the test's transaction, authenticated user and fakes | no | yes | yes | yes | the [demo](https://github.com/sorge-it/http-server/tree/main/demo) for `php -S`; for the others, the handler runs in the test process | | Event loop | none needed by the test | Revolt, with fibers | ReactPHP's loop | none: the test calls `tick()` | [composer.json of amphp/http-server 3.4.9](https://github.com/amphp/http-server/blob/v3.4.9/composer.json), [composer.json of react/http 1.12.0](https://github.com/reactphp/http/blob/v1.12.0/composer.json) | -| Direct dependencies | none for `php -S`, part of PHP; `php artisan serve` is part of `laravel/framework` and starts `php -S` | 13 | 7 | no packages; `ext-filter` of PHP | the same two files | +| Direct dependencies | none for `php -S`, part of PHP; `php artisan serve` is part of `laravel/framework` and starts `php -S` | 13 | 7 | no packages; PHP's `filter` extension | the same two files | | TLS and HTTP/2 | no | TLS and HTTP/2 | TLS, no HTTP/2 | no: HTTP/1.1 on loopback only | [php_cli_server.c of PHP 8.4](https://github.com/php/php-src/blob/php-8.4.0/sapi/cli/php_cli_server.c), [README of amphp/http-server 3.4.9](https://github.com/amphp/http-server/blob/v3.4.9/README.md), [README of react/http 1.12.0](https://github.com/reactphp/http/blob/v1.12.0/README.md) | -| Built for | development and testing, not a public network | application servers | event-driven applications | browser tests on loopback | the PHP manual and the two READMEs | +| What it is | a server for development and testing, not for a public network | an HTTP/1.1 and HTTP/2 application server | a server for ReactPHP's event loop | a server for browser tests on loopback | the PHP manual and the two READMEs | HttpServer follows one server, the pinned official FrankenPHP build over HTTP, and its suites compare the response to each valid request with it. @@ -713,7 +717,7 @@ class lives in the namespace `SorgeIt\HttpServer\Internal` and can change in any | `new Response(int $status = 200, array $headers = [], string\|iterable $body = '', ?string $file = null, bool $deleteFile = false)` | a response. `$headers` maps a name to a string or a list of strings. `$body` is a string, or an iterable of strings that the server streams as they come. `$file` sends a file instead of a body. A redirect needs its status, such as `new Response(303, ['Location' => '/done'])`; status 0 sets none, and then a `Location` gives 302, as in PHP. A status outside 100 to 999 becomes 500 | `ValueError` for a header value that is not a string, an integer header key, or a body and a file together | | `Response::$status`, `$headers`, `$body`, `$file`, `$deleteFile` | the constructor arguments, as public readonly properties, for a test that checks a handler's response | none | | `new Limits(?int $maxHead = null, ?int $maxBody = null, ?float $idleTimeout = null, ?float $headerTimeout = null)` | the limits and timeouts; name the arguments, such as `new Limits(maxBody: 1024)`. Null selects the default, 0 turns a limit off. Defaults: `maxHead` 16 KiB, `maxBody` none, `idleTimeout` 120 s, `headerTimeout` 10 s; see [Limits and timeouts](#limits-and-timeouts) | `ValueError` for a negative value, or a timeout that is not finite or above 1e8 s | -| `ClosedWithErrors::$errors` | the list of `Throwable` that no `onError` received; the first is also the previous exception | none | +| `ClosedWithErrors::$errors` | the list of `Throwable`s that no `onError` received; the first is also the previous exception | none | ### The request body @@ -731,8 +735,8 @@ $request->body->error() === null || throw new RuntimeException($request->body->e parse_str($form, $fields); // for application/x-www-form-urlencoded; a multipart body needs a parser of its own ``` -The rules below follow how Go `net/http` handles `Request.Body`, with exceptions of the -server's own, each marked "(not in Go)". The `GoNetHttp` suite has these cases in its group +The rules below follow how Go `net/http` handles `Request.Body`. Each point marked "(not in Go)" +is the server's own. The `GoNetHttp` suite has these cases in its group `handler`. [How a connection ends](#how-a-connection-ends) covers the unread remainder of a body and a truncated body. @@ -853,10 +857,11 @@ the [scope](#scope) states a rule of the scope. Each point marked "(not in Go)" Every other point describes what Go `net/http` does, and the `GoNetHttp` suite has a case for it. Caddy and the PHP SAPI change the request and the response (see [Layers](#layers-who-decides-what)), so the suite compares the responses with FrankenPHP. Some -points, such as the exact place of a limit, are out of scope; this section describes them as the -server handles them today. +behavior, such as the exact byte at which a limit applies, is out of scope; this section describes +it as the server handles it today. -The reference differs from RFC 9110 and RFC 9112 in three points, and the server follows it: +FrankenPHP, the reference (see [Scope](#scope)), differs from RFC 9110 and RFC 9112 in four +points, and the server follows it: - A request line longer than `maxHead` gets 431. RFC 9112 section 3 names 414 for a request target that is too long. Go counts the request line in `MaxHeaderBytes`. @@ -865,6 +870,7 @@ The reference differs from RFC 9110 and RFC 9112 in three points, and the server - A method longer than 32 bytes gets Caddy's 405, without `Allow`. RFC 9112 section 3 names 501 for a method longer than any the server implements, and RFC 9110 section 15.5.6 requires `Allow` in a 405. +- A 205 sends the handler's body. RFC 9110 section 15.3.6 forbids content in a 205. Go sends it. ### A valid request @@ -913,14 +919,15 @@ The server also sends the 400 for an incomplete request: ### What the server reads -- HTTP/1.1, keep-alive, more than one request in one packet (pipelining), and a request spread over +- HTTP/1.1, keep-alive, more than one request before the first response (pipelining), several + requests in one packet, and a request spread over many packets. The result is the same whether the bytes arrive whole or one at a time. This also applies at each limit. - `maxHead` counts the header section to the byte: the request line, the fields, each with its CRLF, and the empty line. A header section of exactly `maxHead` bytes is accepted; one byte more is rejected with 431, even before the end of the header section arrives. Go reads more than `MaxHeaderBytes`, so FrankenPHP accepts a header section of up to 20,494 bytes; the exact - place of a limit is out of [scope](#scope). + byte at which a limit applies is out of [scope](#scope). - A field value is stripped of surrounding spaces and tabs. A header section can have 500 field values, matching Go's `DefaultMaxHeaderValueCount`; more are rejected with 431. - The server parses the request target as Go's `url.ParseRequestURI` does, and decodes no part of @@ -951,8 +958,8 @@ A negative value, or a timeout that is not finite or above 1e8 s, throws a `Valu #### The default timeouts -The reference is Caddy over HTTP. It uses the default server settings except for two -timeouts, as in the site block `http://127.0.0.1:8080 { php_server }` with +The defaults follow Caddy over HTTP, as FrankenPHP runs it. Apart from two timeouts, Caddy runs +with its default server settings, as in the site block `http://127.0.0.1:8080 { php_server }` with `servers { timeouts { read_header 10s idle 2m } }`. The two timeouts come from a production FrankenPHP site behind a TLS proxy, measured by hand on 2026-11-02; no suite repeats the measurement. A connection without a request, and one with a partial header section, closed after @@ -983,10 +990,10 @@ Caddy's timeouts for each read and write (`ReadIdleTimeout` and `WriteIdleTimeou still gets the responses to all the requests it sent before, including those with a large file. - Once the handler has returned, the server reads and discards the unread remainder of the request body before it writes the response. This applies to every remainder, including one from a - request that closes the connection. This way the server sees every truncated body, as the - [scope](#scope) requires. Go differs; see [Deliberate differences](#deliberate-differences). + request that closes the connection. This way the server sees every truncated body, as + [A valid request](#a-valid-request) requires. Go differs; see [Deliberate differences](#deliberate-differences). - A truncated body, one that a half-close by the client ended before its full length, makes the - request not valid; see [Scope](#scope). The handler gets the error; see + request not valid; see [A valid request](#a-valid-request). The handler gets the error; see [The request body](#the-request-body). Then the server drops the response, sends the 400, and closes. - No timeout runs while the server writes responses. Go also has no `WriteTimeout` by default. @@ -1077,7 +1084,7 @@ adds its own headers, such as `Content-Type`, `X-Powered-By` and Caddy's `Server ## Compatibility with FrankenPHP HttpServer follows the FrankenPHP build that -[`release.lock`](tests/Fixtures/frankenphp/release.lock) pins, one layer at a time. Go `net/http` +[`release.lock`](https://github.com/sorge-it/http-server/blob/main/tests/Fixtures/frankenphp/release.lock) pins, one layer at a time. Go `net/http` parses the request and frames the response, Caddy adds its checks and defaults, and the PHP SAPI sets the script's status and headers, using the test process's php.ini. The `GoNetHttp` suite checks the parser against a Go `net/http` server; the `GoNetHttp` and `FrankenPhp` suites compare each byte @@ -1102,7 +1109,7 @@ Chrome sends such a path unchanged, and the reference rejects it with the same 4 [A valid request](#a-valid-request) states the exact rule. The rule is written by hand: no suite compares it live against Chrome, because such a suite would add too much complexity. The `FrankenPhp` suite applies the rule to the requests Chrome sent, recorded in -[`chrome/`](tests/Fixtures/chrome): each one is valid except the one with an invalid +[`chrome/`](https://github.com/sorge-it/http-server/tree/main/tests/Fixtures/chrome): each one is valid except the one with an invalid percent-encoding. The server detects any request that is not valid and rejects it. Its response does not depend on @@ -1128,7 +1135,7 @@ This question decides whether a behavior is in scope: | The trailers of a response. Chrome drops them, and `fetch` has no API for them | out | | How the reference uses memory | out | | Timing that does not change the result | out | -| The exact place of a limit | out | +| The exact byte at which a limit applies | out | | h2c, HTTP/2, HTTP/3 and TLS. Chrome speaks HTTP/2 and HTTP/3 only over TLS | out | | A request that no browser sends | out | | A listener on an address that is not loopback, such as `::` or `0.0.0.0`, or on an IPv4-mapped IPv6 address, such as `::ffff:127.0.0.1` | out | @@ -1147,7 +1154,8 @@ The server also makes guarantees of its own that go beyond the reference: [Deliberate differences](#deliberate-differences). - A slow or endless streamed response body does not block the other connections. A handler never makes `tick()` throw. A process paused at a breakpoint does not lose a complete header section. - See [Ticking and waiting](#ticking-and-waiting). + See [Ticking and waiting](#ticking-and-waiting) and + [onError and ClosedWithErrors](#onerror-and-closedwitherrors). - `(string) $request->body`, `onError`, `ClosedWithErrors` and `deleteFile` are additions to the reference; see [Deliberate differences](#deliberate-differences). @@ -1266,46 +1274,45 @@ and the suite that tests them. ### The suites The suites that compare live need the Go version and the FrankenPHP binary that -[CONTRIBUTING.md](.github/CONTRIBUTING.md#setup) installs. +[CONTRIBUTING.md](https://github.com/sorge-it/http-server/blob/main/.github/CONTRIBUTING.md#setup) installs. | Suite | What it checks | Compared live with | |---|---|---| | `RequestLine`, `Headers`, `Framing`, `Smuggling`, `Limits`, `Connection`, `Responses`, `Files`, `Handler`, `Transport` | one part of HTTP/1.1 each | FrankenPHP or Go `net/http`, as for `GoNetHttp`, where a test names it | -| `GoNetHttp` | the requests in [`cases.json`](tests/Fixtures/go-net-http/cases.json): those of Go's test files and probes of its rules. The parser must read each one as Go does: whole, one byte at a time, and a case over 256 KiB in pieces of 4,093 bytes. Then mutated requests. A valid request gets FrankenPHP's bytes; any request that is not valid gets the 400 from [Scope](#scope) | for the parser, a Go `net/http` server from `tests/GoNetHttp/reference`; for the responses, the FrankenPHP binary, which runs the same test handler in `tests/FrankenPhp/go/index.php` | -| `FrankenPhp` | the cases in [`cases.json`](tests/Fixtures/frankenphp/cases.json). Each case names, as needed, a php.ini, a status, headers, a body, the ini settings that the handler changes, and an exception. The HTTP/1.0 cases get the 400 from [Scope](#scope). Then Caddy's probes, as for `GoNetHttp`. Then the requests Chrome sent, in [`chrome/`](tests/Fixtures/chrome), on their connections, except those with a multipart body, which PHP parses itself; the one with an invalid percent-encoding gets the 400 from [Scope](#scope) | the FrankenPHP binary, which runs `tests/FrankenPhp/app/index.php`, and for the probes and Chrome's requests `tests/FrankenPhp/go/index.php` | +| `GoNetHttp` | the requests in [`cases.json`](https://github.com/sorge-it/http-server/blob/main/tests/Fixtures/go-net-http/cases.json): those of Go's test files and probes of its rules. The parser must read each one as Go does: whole, one byte at a time, and a case over 256 KiB in pieces of 4,093 bytes. Then mutated requests. A valid request gets FrankenPHP's bytes; any request that is not valid gets the 400 from [Scope](#scope) | for the parser, a Go `net/http` server from `tests/GoNetHttp/reference`; for the responses, the FrankenPHP binary, which runs the same test handler in `tests/FrankenPhp/go/index.php` | +| `FrankenPhp` | the cases in [`cases.json`](https://github.com/sorge-it/http-server/blob/main/tests/Fixtures/frankenphp/cases.json). Each case names, as needed, a php.ini, a status, headers, a body, the ini settings that the handler changes, and an exception. The HTTP/1.0 cases get the 400 from [Scope](#scope). Then Caddy's probes, as for `GoNetHttp`. Then the requests Chrome sent, in [`chrome/`](https://github.com/sorge-it/http-server/tree/main/tests/Fixtures/chrome), on their connections, except those with a multipart body, which PHP parses itself; the one with an invalid percent-encoding gets the 400 from [Scope](#scope) | the FrankenPHP binary, which runs `tests/FrankenPhp/app/index.php`, and for the probes and Chrome's requests `tests/FrankenPhp/go/index.php` | | `BeyondGo` | the string form of the body, the close after a 413, and the PHP state that the handler shares with the test; see [Deliberate differences](#deliberate-differences) | none | | `Api` | which classes are public, and that none of them names an internal class | none | -| `Scope` | the guard for each out-of-scope row of [Scope](#scope), from [`out.php`](tests/Scope/out.php): patterns that the code in `src/`, without its comments, must not contain, and requests that get the 400 from Scope before the client disconnects, or the reason a row has none. It fails when the rows and the guards differ | none | +| `Scope` | the guard for each out-of-scope row of [Scope](#scope), from [`out.php`](https://github.com/sorge-it/http-server/blob/main/tests/Scope/out.php): patterns that the code in `src/`, without its comments, must not contain, and requests that get the 400 from Scope before the client disconnects, or the reason a row has none. It fails when the rows and the guards differ | none | | `Fuzz` | the parser with mutated requests from fixed seeds. It must read each one the same way whole, one byte at a time, and in random packets | none | | `Example` | the examples in this README: each test and script runs, and this README shows its code; the handlers of [Works with](#works-with-symfony-laravel-and-psr-15) run in the weekly `works-with` job. The browser tests `ChromeTest` and `FormTest` use the Chrome that `CHROME` names; without `CHROME`, they are skipped | none | The live suites compare each byte of the responses, with the same `Date` and the same PHP version, in the form that Chrome receives: a chunked body as a single chunk, without trailers. The `FrankenPhp` suite masks the file and the line in an error page but keeps its length. -[`tests/Fixtures/README.md`](tests/Fixtures/README.md) describes the cases, the probes and the lock +[`tests/Fixtures/README.md`](https://github.com/sorge-it/http-server/blob/main/tests/Fixtures/README.md) describes the cases, the probes and the lock files. ## Development -`composer test` runs Pint, Rector, PHPStan at level max, 100% type coverage and the suites. CI adds -100% line coverage, with one block excluded that only another process can reach, and Docker jobs on -Debian and Alpine. Weekly jobs run the mutation tests, with a minimum score of 99%. They also -compare against the newest Caddy and FrankenPHP and against the Go version that the pinned -FrankenPHP uses. One job runs the handlers of [Works with](#works-with-symfony-laravel-and-psr-15) -with the newest Symfony, Laravel and Slim. Every action and every Docker image is pinned to a commit -or a digest. [CONTRIBUTING.md](.github/CONTRIBUTING.md) covers the setup and what a pull request +Weekly jobs check the pins against the newest releases of Caddy and FrankenPHP and run the suites +with them. The weekly `works-with` job runs the handlers of +[Works with Symfony, Laravel and PSR-15](#works-with-symfony-laravel-and-psr-15) with the newest +Symfony, Laravel and Slim. +Every action and every Docker image is pinned to a commit or a digest. +[CONTRIBUTING.md](https://github.com/sorge-it/http-server/blob/main/.github/CONTRIBUTING.md) covers the setup, the tests and what a pull request needs. ## Support Found a bug? Open a pull request with a failing test; a fix is welcome but not required. The issue -tracker is closed; see [CONTRIBUTING.md](.github/CONTRIBUTING.md). Report a vulnerability privately -through GitHub; see [SECURITY.md](.github/SECURITY.md). +tracker is closed; see [CONTRIBUTING.md](https://github.com/sorge-it/http-server/blob/main/.github/CONTRIBUTING.md). Report a vulnerability privately +through GitHub; see the [security policy](https://github.com/sorge-it/http-server/security/policy). ## License MIT; see [LICENSE](LICENSE). The fixtures keep their original licenses; see -[tests/Fixtures/README.md](tests/Fixtures/README.md). +[tests/Fixtures/README.md](https://github.com/sorge-it/http-server/blob/main/tests/Fixtures/README.md). ## About the author diff --git a/composer.json b/composer.json index 1d424be..84974b0 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "sorge-it/http-server", - "description": "In-process HTTP/1.1 server for Pest and PHPUnit browser tests, built for coding agents. The page sees the test's RefreshDatabase transaction, actingAs() user and fakes. No event loop, no package dependencies; tests compare each response to a valid request byte for byte with FrankenPHP. Loopback only; not for production, WebDriver or HTTP mocks.", + "description": "In-process HTTP/1.1 server for Pest and PHPUnit browser tests, built for coding agents. The page sees the test's RefreshDatabase transaction, actingAs() user and fakes. No event loop, no package dependencies; tests compare each response to a valid request with FrankenPHP, byte for byte in the form Chrome receives. Loopback only; not for production, WebDriver or HTTP mocks.", "type": "library", "license": "MIT", "keywords": ["http-server", "http-1.1", "in-process", "psr-15", "zero-dependency", "testing", "browser-testing", "pest", "pestphp", "phpunit", "laravel", "symfony", "refresh-database", "database-transactions", "frankenphp", "chrome", "headless-chrome", "coding-agents", "ai-agents", "agentic-engineering"], diff --git a/tests/Scope/out.php b/tests/Scope/out.php index d224e2d..6cb1b16 100644 --- a/tests/Scope/out.php +++ b/tests/Scope/out.php @@ -40,7 +40,7 @@ 'none' => 'The server measures time of its own. No pattern tells a copy of the reference from its own timing.', ], [ - 'row' => 'The exact place of a limit', + 'row' => 'The exact byte at which a limit applies', 'absent' => [ '/\+\s*4096\b/' => '$left = $this->maxHead + 4096;', '/\+=\s*4096\b/' => '$left += 4096;',