Forward JSON registration POST bodies through the ladl.link proxy.
Deploy Ladill Link / deploy (push) Successful in 41s
Deploy Ladill Link / deploy (push) Successful in 41s
Event signup from ladl.link sends application/json; re-encoding as form data dropped the payload and caused failed registrations to redirect to ladl.link/undefined. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -74,7 +74,7 @@ class LinkPlatformProxy
|
|||||||
->withHeaders($this->forwardHeaders($request));
|
->withHeaders($this->forwardHeaders($request));
|
||||||
|
|
||||||
$pending = match ($method) {
|
$pending = match ($method) {
|
||||||
'POST' => $client->asForm()->post($target, $request->post()),
|
'POST' => $this->forwardPost($client, $request, $target),
|
||||||
'PATCH' => $client->patch($target, $request->all()),
|
'PATCH' => $client->patch($target, $request->all()),
|
||||||
'DELETE' => $client->delete($target),
|
'DELETE' => $client->delete($target),
|
||||||
default => $client->get($target),
|
default => $client->get($target),
|
||||||
@@ -143,12 +143,27 @@ class LinkPlatformProxy
|
|||||||
return array_filter([
|
return array_filter([
|
||||||
'Accept' => $request->header('Accept'),
|
'Accept' => $request->header('Accept'),
|
||||||
'Accept-Language' => $request->header('Accept-Language'),
|
'Accept-Language' => $request->header('Accept-Language'),
|
||||||
|
'Content-Type' => $request->header('Content-Type'),
|
||||||
'User-Agent' => $request->header('User-Agent'),
|
'User-Agent' => $request->header('User-Agent'),
|
||||||
'Referer' => $request->header('Referer'),
|
'Referer' => $request->header('Referer'),
|
||||||
self::INTERNAL_HEADER => '1',
|
self::INTERNAL_HEADER => '1',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function forwardPost(\Illuminate\Http\Client\PendingRequest $client, Request $request, string $target): \Illuminate\Http\Client\Response
|
||||||
|
{
|
||||||
|
if ($this->requestSendsJson($request)) {
|
||||||
|
return $client->asJson()->post($target, $request->all());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $client->asForm()->post($target, $request->post());
|
||||||
|
}
|
||||||
|
|
||||||
|
private function requestSendsJson(Request $request): bool
|
||||||
|
{
|
||||||
|
return str_contains(strtolower((string) $request->header('Content-Type', '')), 'application/json');
|
||||||
|
}
|
||||||
|
|
||||||
/** @param array<string, array<int, string>> $headers */
|
/** @param array<string, array<int, string>> $headers */
|
||||||
private function sanitizeHeaders(array $headers): array
|
private function sanitizeHeaders(array $headers): array
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -154,4 +154,52 @@ class LinkRedirectTest extends TestCase
|
|||||||
return str_starts_with($request->url(), 'https://ladill.com/q/sales-webinar/registered/');
|
return str_starts_with($request->url(), 'https://ladill.com/q/sales-webinar/registered/');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_event_registration_post_forwards_json_body_to_events(): void
|
||||||
|
{
|
||||||
|
$user = $this->user();
|
||||||
|
ShortLink::create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'slug' => 'sales-webinar',
|
||||||
|
'source_app' => 'events',
|
||||||
|
'source_kind' => 'qr',
|
||||||
|
'is_managed_here' => false,
|
||||||
|
'destination_url' => 'https://ladl.link/sales-webinar',
|
||||||
|
'is_active' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
Http::fake([
|
||||||
|
'https://events.ladill.com/q/sales-webinar/register' => function ($request) {
|
||||||
|
$payload = json_decode($request->body(), true);
|
||||||
|
|
||||||
|
return Http::response(json_encode([
|
||||||
|
'paid' => false,
|
||||||
|
'success_url' => 'https://ladl.link/sales-webinar/registered/QRE-TESTREF123456',
|
||||||
|
'badge_code' => 'BADGE123',
|
||||||
|
]), 200, ['Content-Type' => 'application/json']);
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->postJson('https://ladl.link/sales-webinar/register', [
|
||||||
|
'tier' => 'General Admission',
|
||||||
|
'attendee_name' => 'Jane Doe',
|
||||||
|
'attendee_email' => 'jane@example.com',
|
||||||
|
'attendee_phone' => '+233200000000',
|
||||||
|
])
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonPath('success_url', 'https://ladl.link/sales-webinar/registered/QRE-TESTREF123456');
|
||||||
|
|
||||||
|
Http::assertSent(function ($request) {
|
||||||
|
if ($request->url() !== 'https://events.ladill.com/q/sales-webinar/register') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$payload = json_decode($request->body(), true);
|
||||||
|
|
||||||
|
return is_array($payload)
|
||||||
|
&& ($payload['attendee_email'] ?? '') === 'jane@example.com'
|
||||||
|
&& ($payload['tier'] ?? '') === 'General Admission'
|
||||||
|
&& $request->hasHeader('X-Ladill-Internal', '1');
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user