Skip to content

Commit 9a72241

Browse files
chore(client): send metadata headers
1 parent 574d168 commit 9a72241

File tree

3 files changed

+65
-2
lines changed

3 files changed

+65
-2
lines changed

release-please-config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
],
6262
"release-type": "php",
6363
"extra-files": [
64-
"README.md"
64+
"README.md",
65+
"src/Client.php"
6566
]
6667
}

src/Client.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,19 @@ public function __construct(?string $apiKey = null, ?string $baseUrl = null)
4040
);
4141

4242
parent::__construct(
43+
// x-release-please-start-version
4344
headers: [
44-
'Content-Type' => 'application/json', 'Accept' => 'application/json',
45+
'Content-Type' => 'application/json',
46+
'Accept' => 'application/json',
47+
'User-Agent' => sprintf('CAS Parser/PHP %s', '0.0.1'),
48+
'X-Stainless-Lang' => 'php',
49+
'X-Stainless-Package-Version' => '0.0.1',
50+
'X-Stainless-OS' => $this->getNormalizedOS(),
51+
'X-Stainless-Arch' => $this->getNormalizedArchitecture(),
52+
'X-Stainless-Runtime' => 'php',
53+
'X-Stainless-Runtime-Version' => phpversion(),
4554
],
55+
// x-release-please-end
4656
baseUrl: $baseUrl,
4757
options: $options,
4858
);

src/Core/BaseClient.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,56 @@ public function request(
105105
/** @return array<string, string> */
106106
abstract protected function authHeaders(): array;
107107

108+
protected function getNormalizedOS(): string
109+
{
110+
$os = strtolower(PHP_OS_FAMILY);
111+
112+
switch ($os) {
113+
case 'windows':
114+
return 'Windows';
115+
116+
case 'darwin':
117+
return 'MacOS';
118+
119+
case 'linux':
120+
return 'Linux';
121+
122+
case 'bsd':
123+
case 'freebsd':
124+
case 'openbsd':
125+
return 'BSD';
126+
127+
case 'solaris':
128+
return 'Solaris';
129+
130+
case 'unix':
131+
case 'unknown':
132+
return 'Unknown';
133+
134+
default:
135+
return 'Other:'.$os;
136+
}
137+
}
138+
139+
protected function getNormalizedArchitecture(): string
140+
{
141+
$arch = php_uname('m');
142+
if (false !== strpos($arch, 'x86_64') || false !== strpos($arch, 'amd64')) {
143+
return 'x64';
144+
}
145+
if (false !== strpos($arch, 'i386') || false !== strpos($arch, 'i686')) {
146+
return 'x32';
147+
}
148+
if (false !== strpos($arch, 'aarch64') || false !== strpos($arch, 'arm64')) {
149+
return 'arm64';
150+
}
151+
if (false !== strpos($arch, 'arm')) {
152+
return 'arm';
153+
}
154+
155+
return 'unknown';
156+
}
157+
108158
/**
109159
* @internal
110160
*
@@ -238,6 +288,8 @@ protected function sendRequest(
238288
): ResponseInterface {
239289
assert(null !== $opts->streamFactory && null !== $opts->transporter);
240290

291+
$req = $req->withHeader('X-Stainless-Retry-Count', strval($retryCount));
292+
241293
$req = Util::withSetBody($opts->streamFactory, req: $req, body: $data);
242294

243295
$rsp = null;

0 commit comments

Comments
 (0)