Skip to content

fix: set canonical User-Agent header format#99

Merged
gjtorikian merged 1 commit into
mainfrom
add-id-header
May 2, 2026
Merged

fix: set canonical User-Agent header format#99
gjtorikian merged 1 commit into
mainfrom
add-id-header

Conversation

@gjtorikian
Copy link
Copy Markdown
Contributor

Summary

The Tesla middleware was sending no User-Agent header on outgoing requests. This adds one in the canonical WorkOS SDK format: workos-elixir/{VERSION}, with the version pulled from the application spec.

Test plan

  • Manual verification: Application.spec(:workos, :vsn) returns the charlist version (e.g. ~c"1.2.1"), and Elixir's String.Chars.List implementation converts charlists to a binary on #{} interpolation, so the resulting header value is workos-elixir/1.2.1.
  • Confirm User-Agent on a real outgoing request

🤖 Generated with Claude Code

The Tesla middleware was sending no `User-Agent` header on
outgoing requests, leaving them indistinguishable from
unrelated traffic. Sets the header to
`workos-elixir/{VERSION}`, matching WorkOS' canonical SDK
User-Agent format.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@gjtorikian gjtorikian marked this pull request as ready for review May 2, 2026 14:36
@gjtorikian gjtorikian requested a review from a team as a code owner May 2, 2026 14:36
@gjtorikian gjtorikian merged commit 460a2fb into main May 2, 2026
5 checks passed
@gjtorikian gjtorikian deleted the add-id-header branch May 2, 2026 14:36
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 2, 2026

Greptile Summary

This PR adds a User-Agent: workos-elixir/{VERSION} header to all outgoing Tesla HTTP requests by introducing a private user_agent/0 helper that reads the version at runtime via Application.spec(:workos, :vsn). The change is minimal and correct — charlist interpolation in Elixir produces the expected binary string.

Confidence Score: 4/5

Safe to merge; only a P2 nil-safety suggestion on the version lookup.

The change is small and focused with no logic errors or security concerns. The sole finding is a P2 style suggestion to guard against a nil version string in edge-case environments.

No files require special attention.

Important Files Changed

Filename Overview
lib/workos/client/tesla_client.ex Adds User-Agent: workos-elixir/{VERSION} header via a new private user_agent/0 helper; minor concern around nil-safety of Application.spec/2.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant TeslaClient
    participant Tesla
    participant WorkOS API

    Caller->>TeslaClient: request(client, opts)
    TeslaClient->>TeslaClient: user_agent() → "workos-elixir/1.2.1"
    TeslaClient->>Tesla: Tesla.client([..., Headers: [Authorization, User-Agent]])
    Tesla->>WorkOS API: HTTP request with User-Agent: workos-elixir/1.2.1
    WorkOS API-->>Tesla: Response
    Tesla-->>Caller: {:ok, response}
Loading

Reviews (1): Last reviewed commit: "fix: set canonical User-Agent header for..." | Re-trigger Greptile

end

defp user_agent do
"workos-elixir/#{Application.spec(:workos, :vsn)}"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Guard against nil version

Application.spec(:workos, :vsn) returns nil when the application is not loaded (e.g. in certain test setups or as a library dependency that hasn't started). Interpolating nil yields "workos-elixir/", which is a malformed User-Agent. A compile-time attribute or a runtime fallback would be safer.

Suggested change
"workos-elixir/#{Application.spec(:workos, :vsn)}"
version = Application.spec(:workos, :vsn) || "unknown"
"workos-elixir/#{version}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant