Export HTTPClient field for custom http.Client injection#46
Export HTTPClient field for custom http.Client injection#46heardbefore wants to merge 1 commit intokothar:masterfrom
Conversation
Replace the unexported httpClient http.Client value field with an exported HTTPClient *http.Client pointer field. When nil, the client falls back to http.DefaultClient, preserving existing behavior. This enables callers to inject a custom *http.Client with a wrapped Transport, which is useful for setting custom User-Agent headers, configuring TLS, or adding observability middleware. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughRefactors the B2 struct's HTTP client management by introducing a configurable exported Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.11.4)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies" Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
httpClient http.Clientvalue field on theB2struct with an exportedHTTPClient *http.Clientpointer fieldHTTPClientis nil, the client falls back tohttp.DefaultClient, preserving existing behavior for all current usershttpClient()helper that returns the effective clientMotivation
Callers currently have no way to customize the HTTP client used by
B2. This makes it impossible to:User-Agentheader (needed for Backblaze's integration checklist)This is a minimal, backwards-compatible change — the only breaking aspect is that code directly initializing the unexported
httpClientfield in struct literals (which is only possible within this package) now uses the exported name.Test plan
HTTPClientfieldgo test ./...passes (all tests usehttptest.Serverwith a custom client, which now goes through the exported field)🤖 Generated with Claude Code
Summary by CodeRabbit