Skip to content

Commit 08f842a

Browse files
authored
fix base URI concatenation so path isn't lost (#96)
* fix base URI concatenation so path isn't lost * also fix base URIs for events
1 parent ee95057 commit 08f842a

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

src/LaunchDarkly/Impl/Integrations/CurlEventPublisher.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ public function __construct(string $sdkKey, array $options = [])
4141
{
4242
$this->_sdkKey = $sdkKey;
4343

44-
$eventsUri = LDClient::DEFAULT_EVENTS_URI;
45-
if (isset($options['events_uri'])) {
46-
$eventsUri = $options['events_uri'];
44+
$baseUri = $options['events_uri'] ?? null;
45+
if (!$baseUri) {
46+
$baseUri = LDClient::DEFAULT_EVENTS_URI;
4747
}
48+
$eventsUri = \LaunchDarkly\Impl\Util::adjustBaseUri($baseUri);
49+
4850
$url = parse_url(rtrim($eventsUri, '/'));
4951
$this->_host = $url['host'] ?? '';
5052
$this->_ssl = ($url['scheme'] ?? '') === 'https';

src/LaunchDarkly/Impl/Integrations/GuzzleEventPublisher.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ public function __construct(string $sdkKey, array $options = [])
2828
{
2929
$this->_sdkKey = $sdkKey;
3030
$this->_logger = $options['logger'];
31-
if (isset($options['events_uri'])) {
32-
$this->_eventsUri = $options['events_uri'];
33-
} else {
34-
$this->_eventsUri = LDClient::DEFAULT_EVENTS_URI;
31+
32+
$baseUri = $options['events_uri'] ?? null;
33+
if (!$baseUri) {
34+
$baseUri = LDClient::DEFAULT_EVENTS_URI;
3535
}
36+
$this->_eventsUri = \LaunchDarkly\Impl\Util::adjustBaseUri($baseUri);
37+
3638
$this->_requestOptions = [
3739
'headers' => [
3840
'Content-Type' => 'application/json',
@@ -53,7 +55,7 @@ public function publish(string $payload): bool
5355
try {
5456
$options = $this->_requestOptions;
5557
$options['body'] = $payload;
56-
$response = $client->request('POST', '/bulk', $options);
58+
$response = $client->request('POST', 'bulk', $options);
5759
} catch (\Exception $e) {
5860
$this->_logger->warning("GuzzleEventPublisher::publish caught $e");
5961
return false;

src/LaunchDarkly/Impl/Integrations/GuzzleFeatureRequester.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
*/
2222
class GuzzleFeatureRequester implements FeatureRequester
2323
{
24-
const SDK_FLAGS = "/sdk/flags";
25-
const SDK_SEGMENTS = "/sdk/segments";
24+
const SDK_FLAGS = "sdk/flags";
25+
const SDK_SEGMENTS = "sdk/segments";
2626
/** @var Client */
2727
private $_client;
2828
/** @var LoggerInterface */
@@ -32,6 +32,8 @@ class GuzzleFeatureRequester implements FeatureRequester
3232

3333
public function __construct(string $baseUri, string $sdkKey, array $options)
3434
{
35+
$baseUri = \LaunchDarkly\Impl\Util::adjustBaseUri($baseUri);
36+
3537
$this->_logger = $options['logger'];
3638
$stack = HandlerStack::create();
3739
if (class_exists('\Kevinrob\GuzzleCache\CacheMiddleware')) {

src/LaunchDarkly/Impl/Util.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
*/
1414
class Util
1515
{
16+
public static function adjustBaseUri(string $uri): string
17+
{
18+
if (substr($uri, strlen($uri) - 1, 1) == '/') {
19+
return $uri;
20+
}
21+
return $uri . '/'; // ensures that subpaths are concatenated correctly
22+
}
23+
1624
public static function dateTimeToUnixMillis(DateTime $dateTime): int
1725
{
1826
$timeStampSeconds = (int)$dateTime->getTimestamp();

0 commit comments

Comments
 (0)