Migrate outbound HTTP calls from Guzzle to the Http facade

Replaces every raw GuzzleHttp\Client usage (Nominatim, web.archive.org,
webmention fetch/discover/send, Bridgy syndication, IndieAuth client_id
lookup, contact avatar/h-card fetch, profile image download, and the
CloudConvert screenshot pipeline) with Illuminate\Support\Facades\Http,
and enables Http::preventStrayRequests() globally in tests so any
un-faked outbound call now fails loudly instead of silently hitting the
network.

The CloudConvert retry-until-finished middleware in AppServiceProvider
is replaced by a plain polling loop in SaveScreenshot, which also fixes
a latent bug where the old middleware decoded a response object instead
of its body. Bridgy syndication jobs keep their tries=1/no-retry
semantics unchanged to avoid duplicate publishes. Guzzle's PSR-7 helpers
(Header, UriResolver, Utils) stay in SendWebMentions since Http has no
equivalent for them.

Every affected test file's Guzzle MockHandler/HandlerStack boilerplate
is replaced with Http::fake()/Http::sequence().

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P8j7cJhCiYDsGUgB7obKNQ
This commit is contained in:
Jonny Barnes 2026-07-26 09:12:01 +01:00
commit e08763c526
Signed by: jonny
SSH key fingerprint: SHA256:CTuSlns5U7qlD9jqHvtnVmfYV3Zwl2Z7WnJ4/dqOaL8
26 changed files with 337 additions and 630 deletions

View file

@ -6,10 +6,7 @@ namespace Tests\Unit\Jobs;
use App\Jobs\SendWebMentions;
use App\Models\Note;
use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use Illuminate\Support\Facades\Http;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
@ -28,12 +25,9 @@ class SendWebMentionJobTest extends TestCase
public function discover_webmention_endpoint_from_header_links(): void
{
$url = 'https://example.org/webmention';
$mock = new MockHandler([
new Response(200, ['Link' => '<'.$url.'>; rel="webmention"']),
Http::fake([
'*' => Http::response('', 200, ['Link' => '<'.$url.'>; rel="webmention"']),
]);
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
$this->app->instance(Client::class, $client);
$job = new SendWebMentions(new Note);
$this->assertEquals($url, $job->discoverWebmentionEndpoint('https://example.org'));
@ -43,12 +37,9 @@ class SendWebMentionJobTest extends TestCase
public function discover_webmention_endpoint_from_html_link_tags(): void
{
$html = '<link rel="webmention" href="https://example.org/webmention">';
$mock = new MockHandler([
new Response(200, [], $html),
Http::fake([
'*' => Http::response($html, 200),
]);
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
$this->app->instance(Client::class, $client);
$job = new SendWebMentions(new Note);
$this->assertEquals(
@ -61,12 +52,9 @@ class SendWebMentionJobTest extends TestCase
public function discover_webmention_endpoint_from_legacy_html_markup(): void
{
$html = '<link rel="http://webmention.org/" href="https://example.org/webmention">';
$mock = new MockHandler([
new Response(200, [], $html),
Http::fake([
'*' => Http::response($html, 200),
]);
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
$this->app->instance(Client::class, $client);
$job = new SendWebMentions(new Note);
$this->assertEquals(
@ -95,13 +83,10 @@ class SendWebMentionJobTest extends TestCase
public function we_send_a_webmention_for_a_note(): void
{
$html = '<link rel="http://webmention.org/" href="https://example.org/webmention">';
$mock = new MockHandler([
new Response(200, [], $html),
new Response(202),
Http::fake([
'example.org/webmention' => Http::response('', 202),
'*' => Http::response($html, 200),
]);
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
$this->app->instance(Client::class, $client);
$note = new Note;
$note->note = 'Hi [Aaron](https://aaronparecki.com)';
@ -114,13 +99,10 @@ class SendWebMentionJobTest extends TestCase
#[Test]
public function links_in_notes_can_not_support_webmentions(): void
{
$mock = new MockHandler([
Http::fake([
// URLs with commas currently break the parse function Im using
new Response(200, ['Link' => '<https://example.org/foo,bar>; rel="preconnect"']),
'*' => Http::response('', 200, ['Link' => '<https://example.org/foo,bar>; rel="preconnect"']),
]);
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
$this->app->instance(Client::class, $client);
$job = new SendWebMentions(new Note);
$this->assertNull($job->discoverWebmentionEndpoint('https://example.org'));