You can register custom scheme/protocols and intercept standard one.
This API allows you to intercept all calls to addresses according to registered schemes and send custom responses generated entirely programmatically, without actual requests to the server (without network).
Registration
To enable processing of specific protocols, you should specify them in the list of schemes.
After enabling the interception of all the necessary protocols (in this case, test), you can start catching the corresponding events of sending requests to this protocol (to this scheme).
use Boson\WebView\Api\Schemes\Event\SchemeRequestReceived;
$app = new Boson\Application(new Boson\ApplicationCreateInfo(
// List of intecpted schemes
schemes: [ 'test' ],
));
$app->on(function (SchemeRequestReceived $e): void {
echo sprintf("%s %s\r\n", $e->request->method, $e->request->url);
foreach ($e->request->headers as $header => $value) {
echo sprintf("%s: %s\r\n", $header, $value);
}
echo sprintf("\r\n\r\n%s", $e->request->body);
//
// Result may looks like:
//
// GET test://hello.world/
// accept: text/html,application/xhtml+xml,application/xml;q=0.9,etc...
// upgrade-insecure-requests: 1
// user-agent: Mozilla/5.0 etc...
// sec-ch-ua: "Microsoft Edge WebView2";v="135", etc...
// sec-ch-ua-mobile: ?0
// sec-ch-ua-platform: "Windows"
//
});
$app->webview->url = 'test://hello.world/';
In that case, if you need to block a request to a specified URL, you can cancel it.