Skip to content

Commit fb55555

Browse files
haretonjmeta-codesync[bot]
authored andcommitted
Return null event_source_url when scheme is missing
Summary: Update `constructEventSourceUrl()` to return null when `$data->scheme` is empty, instead of defaulting to `"http"`. If scheme is null/empty, it means the adaptor was not called or no scheme data is available — defaulting to `"http"` would produce a potentially incorrect URL. The adaptor (`RequestContextAdaptor::extract()`) already guarantees a non-null scheme (`"http"` or `"https"`) when server context is available. The fallback to `"http"` belongs in the adaptor, not in the URL construction logic. Changes: - `constructEventSourceUrl()`: Add `empty($data->scheme)` to the null guard - `constructEventSourceUrl()`: Use `$data->scheme` directly instead of `$data->scheme ?? "http"` - `EventSourceUrlTest.php`: Update tests that previously expected `"http://..."` when scheme was null to expect null instead Reviewed By: jyou23github Differential Revision: D105385176 fbshipit-source-id: 69c28d7c1a3d0dde08c54796d70480881cc97bc9
1 parent 0b563cb commit fb55555

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

php/capi-param-builder/src/ParamBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,12 +357,12 @@ public function getEventSourceUrl()
357357

358358
private function constructEventSourceUrl($data)
359359
{
360-
if ($data === null || empty($data->host)) {
360+
if ($data === null || empty($data->host) || empty($data->scheme)) {
361361
$this->event_source_url = null;
362362
return;
363363
}
364364

365-
$url = ($data->scheme ?? 'http') . '://';
365+
$url = $data->scheme . '://';
366366
$url .= $data->host;
367367

368368
if (!empty($data->request_uri)) {

php/capi-param-builder/tests/EventSourceUrlTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ public function testEventSourceUrlHttpWithHostAndUri(): void
294294
$this->assertEquals('http://www.example.com/path', $builder->getEventSourceUrl());
295295
}
296296

297-
public function testEventSourceUrlHttpWhenSchemeNull(): void
297+
public function testEventSourceUrlNullWhenSchemeNull(): void
298298
{
299299
$builder = new ParamBuilder();
300300
$data = new PlainDataObject(
@@ -308,7 +308,7 @@ public function testEventSourceUrlHttpWhenSchemeNull(): void
308308
'/path'
309309
);
310310
$builder->processRequestFromContext($data);
311-
$this->assertEquals('http://www.example.com/path', $builder->getEventSourceUrl());
311+
$this->assertNull($builder->getEventSourceUrl());
312312
}
313313

314314
public function testEventSourceUrlNullWhenAllNull(): void
@@ -328,7 +328,7 @@ public function testEventSourceUrlNullWhenAllNull(): void
328328
$this->assertNull($builder->getEventSourceUrl());
329329
}
330330

331-
public function testEventSourceUrlHostOnly(): void
331+
public function testEventSourceUrlNullWhenHostOnlyNoScheme(): void
332332
{
333333
$builder = new ParamBuilder();
334334
$data = new PlainDataObject(
@@ -342,7 +342,7 @@ public function testEventSourceUrlHostOnly(): void
342342
null
343343
);
344344
$builder->processRequestFromContext($data);
345-
$this->assertEquals('http://host.example.com', $builder->getEventSourceUrl());
345+
$this->assertNull($builder->getEventSourceUrl());
346346
}
347347

348348
public function testEventSourceUrlPreservesQueryString(): void

0 commit comments

Comments
 (0)