Skip to content

Commit d6235c1

Browse files
feat: support setting headers via env
1 parent 4e816f6 commit d6235c1

1 file changed

Lines changed: 24 additions & 11 deletions

File tree

src/Client.php

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,31 @@ public function __construct(
6363
$requestOptions,
6464
);
6565

66+
/** @var array<string, string|null> $headers */
67+
$headers = [
68+
'Content-Type' => 'application/json',
69+
'Accept' => 'application/json',
70+
'User-Agent' => sprintf('stagehand/PHP %s', VERSION),
71+
'X-Stainless-Lang' => 'php',
72+
'X-Stainless-Package-Version' => '3.19.3',
73+
'X-Stainless-Arch' => Util::machtype(),
74+
'X-Stainless-OS' => Util::ostype(),
75+
'X-Stainless-Runtime' => php_sapi_name(),
76+
'X-Stainless-Runtime-Version' => phpversion(),
77+
];
78+
79+
$customHeadersEnv = Util::getenv('STAGEHAND_CUSTOM_HEADERS');
80+
if (null !== $customHeadersEnv) {
81+
foreach (explode("\n", $customHeadersEnv) as $line) {
82+
$colon = strpos($line, ':');
83+
if (false !== $colon) {
84+
$headers[trim(substr($line, 0, $colon))] = trim(substr($line, $colon + 1));
85+
}
86+
}
87+
}
88+
6689
parent::__construct(
67-
headers: [
68-
'Content-Type' => 'application/json',
69-
'Accept' => 'application/json',
70-
'User-Agent' => sprintf('stagehand/PHP %s', VERSION),
71-
'X-Stainless-Lang' => 'php',
72-
'X-Stainless-Package-Version' => '3.1.0',
73-
'X-Stainless-Arch' => Util::machtype(),
74-
'X-Stainless-OS' => Util::ostype(),
75-
'X-Stainless-Runtime' => php_sapi_name(),
76-
'X-Stainless-Runtime-Version' => phpversion(),
77-
],
90+
headers: $headers,
7891
baseUrl: $baseUrl,
7992
options: $options
8093
);

0 commit comments

Comments
 (0)