fix: add default User-Agent header and optional override#352
fix: add default User-Agent header and optional override#352gjtorikian merged 2 commits intomainfrom
Conversation
Every outbound request now sends a User-Agent identifying the SDK (e.g. "WorkOS PHP/5.0.0"), sourced from Version::SDK_IDENTIFIER / Version::SDK_VERSION. Wrappers like workos-php-laravel can supply their own identifier via a new optional userAgent parameter on the WorkOS constructor, and individual requests can still override via RequestOptions::extraHeaders. Precedence: per-request extraHeaders > per-client constructor arg > default from Version. Note: lib/WorkOS.php is oagen-generated; the oagen template needs the same constructor param + forwarding change so the next regeneration doesn't clobber this. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Greptile SummaryAdds a default Confidence Score: 4/5Safe to merge after addressing the previously-flagged empty-string All new findings in this pass are P2. However, the P1 empty-string edge case raised in a prior review thread (passing lib/HttpClient.php — the Important Files Changed
Sequence DiagramsequenceDiagram
participant Caller
participant WorkOS
participant HttpClient
participant Guzzle
Caller->>WorkOS: new WorkOS(userAgent: "WorkOS PHP Laravel/5.1.0")
WorkOS->>HttpClient: new HttpClient(..., userAgent: "WorkOS PHP Laravel/5.1.0")
Caller->>WorkOS: getOrganization('org_123', RequestOptions?)
WorkOS->>HttpClient: request(...)
HttpClient->>HttpClient: buildRequestOptions()
Note over HttpClient: 1. Set Content-Type, Authorization
Note over HttpClient: 2. Merge extraHeaders (may include User-Agent)
Note over HttpClient: 3. Overwrite User-Agent last<br/>→ $userAgent ?? "WorkOS PHP/5.0.0"
HttpClient->>Guzzle: request(headers: {User-Agent: "WorkOS PHP Laravel/5.1.0", ...})
Guzzle-->>HttpClient: Response
HttpClient-->>WorkOS: decoded array
WorkOS-->>Caller: result
Reviews (2): Last reviewed commit: "fix: preserve UA string versioning" | Re-trigger Greptile |
Pass the Laravel package's Version::SDK_IDENTIFIER and SDK_VERSION as the userAgent constructor argument so every request originating from this package is sent with `User-Agent: WorkOS PHP Laravel/<version>`. This restores the SDK distinguishability that was lost when v5 of workos/workos-php removed the static `WorkOS::setIdentifier` helper. Requires workos/workos-php >= 5.0.1, which adds the userAgent constructor parameter (workos/workos-php#352). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
v5 accidentally dropped the outbound
User-Agentheader identifying the SDK.This is now restored, resulting in
"WorkOS PHP/<Version::SDK_VERSION>"sourced fromlib/Version.php. Previously noUser-Agentwas sent at all, so server-side telemetry couldn't distinguish SDK traffic from other PHP clients.