Skip to content

Conversation

@gagantrivedi
Copy link
Member

@gagantrivedi gagantrivedi commented Oct 31, 2025

Add explicit User-Agent header to all HTTP requests made by the SDK.
The header follows the format: flagsmith-rust-sdk/

Implementation details:

  • Created get_user_agent() function that reads version from CARGO_PKG_VERSION at compile time using option_env! macro
  • Falls back to "flagsmith-rust-sdk/unknown" if version unavailable
  • User-Agent header is added to default headers in Flagsmith client constructor
  • Header is automatically included in both API requests and analytics calls

Testing:

  • Added test_get_user_agent_format() to verify the function returns correct format and actual version (not "unknown") during cargo test

  • Added test_user_agent_header_is_set() to verify the header is sent in HTTP requests using httpmock

    Manual Testing:
    To verify the User-Agent header implementation, we created a standalone Rust application that uses the SDK to make API calls. The headers received by the test server are shown below:

  > 2025/10/31 13:21:00.000054307  length=176 from=0 to=175
GET /any/pathflags/ HTTP/1.1\r
accept: */*\r
x-environment-key: dummy_key_for_demo\r
content-type: application/json\r
user-agent: flagsmith-rust-sdk/2.0.0\r
host: localhost:8080\r
\r

Add explicit User-Agent header to all HTTP requests made by the SDK.
The header follows the format: flagsmith-rust-sdk/<version>

Implementation details:
- Created get_user_agent() function that reads version from CARGO_PKG_VERSION
  at compile time using option_env! macro
- Falls back to "flagsmith-rust-sdk/unknown" if version unavailable
- User-Agent header is added to default headers in Flagsmith client constructor
- Header is automatically included in both API requests and analytics calls

Testing:
- Added test_get_user_agent_format() to verify the function returns correct format
  and actual version (not "unknown") during cargo test
- Added test_user_agent_header_is_set() to verify the header is sent in HTTP
  requests using httpmock
@gagantrivedi gagantrivedi requested a review from a team as a code owner October 31, 2025 07:56
@gagantrivedi gagantrivedi requested review from Zaimwa9 and removed request for a team October 31, 2025 07:57
@gagantrivedi gagantrivedi linked an issue Oct 31, 2025 that may be closed by this pull request
@gagantrivedi gagantrivedi requested a review from a team October 31, 2025 08:02
@gagantrivedi gagantrivedi merged commit 8606c34 into main Nov 4, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Send a standard User-Agent: sdk-name/version header

3 participants