Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@developerkunal
Copy link
Contributor

πŸ”§ Changes

This PR fixes multiple issues related to HTTP headers and request options in the SDK:

User-Agent Header

  • Changed: Management client now uses internal.UserAgentTransport() to set User-Agent header via transport wrapper
  • Fixed: User-Agent now correctly shows as Go-Auth0/v2.0.0 instead of Go-http-client/1.1
  • Why: Transport wrappers ensure headers are set reliably at the transport layer, preventing them from being overwritten

Auth0-Client Header

  • Changed: Management client now uses internal.Auth0ClientInfoTransport() for Auth0-Client header
  • Why: Using transport wrapper instead of WithHTTPHeader ensures the header cannot be accidentally overwritten by user options

Request Options - Merging Behavior

  • Fixed: HTTPHeaderOption now merges headers instead of replacing the entire header map
  • Fixed: BodyPropertiesOption now merges properties instead of replacing
  • Fixed: QueryParametersOption now merges query parameters instead of replacing
  • Why: Multiple option calls should add to each other, not overwrite. This matches the documented behavior in EXAMPLES.md

Debug Logging

  • Fixed: DebugTransport now dumps request after inner transports modify it
  • Why: Debug logs now show the actual headers that were sent (including User-Agent and Auth0-Client)

Code Cleanup

  • Removed: Unused imports (encoding/base64, encoding/json) from management.go

πŸ“š References

This addresses issues where:

  • User-Agent header was not being set correctly in management API requests
  • Debug logs showed incomplete header information
  • Multiple WithHTTPHeader/WithBodyProperties/WithQueryParameters calls would overwrite instead of merge

πŸ”¬ Testing

Existing Tests: All existing tests pass

  • go test ./internal/client/... -run TestDebug - βœ… Pass
  • go test ./management/client/... - βœ… Pass
  • make lint - βœ… Pass

Manual Testing:
Created test client with debug logging enabled and verified:

  • User-Agent header shows as Go-Auth0/v2.0.0 in debug output
  • Auth0-Client header is present in debug output
  • Multiple option calls properly merge instead of replace

Test Scenario:

client, _ := mgmtclient.New(domain,
    option.WithDebug(true),
    option.WithInsecure(),
)
client.Clients.List(ctx, &management.ListClientsRequestParameters{})

Before: Debug log showed User-Agent: Go-http-client/1.1
After: Debug log shows User-Agent: Go-Auth0/v2.0.0

πŸ“ Checklist

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

- Set User-Agent header using transport wrapper instead of option
- Use UserAgentTransport to ensure User-Agent (Go-Auth0/version) is set on all requests
- Use Auth0ClientInfoTransport for Auth0-Client header instead of WithHTTPHeader
- Fix HTTPHeaderOption to merge headers instead of replacing entire map
- Fix BodyPropertiesOption to merge properties instead of replacing
- Fix QueryParametersOption to merge query parameters instead of replacing
- Fix DebugTransport to dump request after transports modify it
- Ensures debug logs show correct User-Agent and Auth0-Client headers

This prevents multiple WithHTTPHeader/WithBodyProperties/WithQueryParameters
calls from overwriting each other, and ensures base options don't get
overwritten by user options.

Fixes issues where:
- User-Agent header was showing as 'Go-http-client/1.1' instead of 'Go-Auth0/v2.0.0'
- Debug logs were showing request before transports modified headers
- Multiple option calls would overwrite instead of merge
@developerkunal developerkunal requested a review from a team as a code owner October 9, 2025 18:57
@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 59.52381% with 17 lines in your changes missing coverage. Please review.
βœ… Project coverage is 24.11%. Comparing base (cae5b1d) to head (75439f2).

Files with missing lines Patch % Lines
management/core/request_option.go 19.04% 16 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #625   +/-   ##
=======================================
  Coverage   24.11%   24.11%           
=======================================
  Files         295      295           
  Lines      103365   103388   +23     
=======================================
+ Hits        24922    24933   +11     
- Misses      76694    76706   +12     
  Partials     1749     1749           

β˜” View full report in Codecov by Sentry.
πŸ“’ Have feedback on the report? Share it here.

πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@developerkunal developerkunal merged commit f3d724e into main Oct 10, 2025
4 checks passed
@developerkunal developerkunal deleted the feat/fix-user-agent-and-option-merging branch October 10, 2025 11:26
@developerkunal developerkunal mentioned this pull request Oct 13, 2025
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.

4 participants