Extract shared HTTP logic into doHTTP#70
Merged
Conversation
Both CustomerIO.request() and APIClient.doRequest() duplicated the same marshal → create request → set headers → execute → read body pipeline. Extract doHTTP() that accepts an auth callback, then have both clients delegate to it. Auth (Basic vs Bearer) and error handling remain caller-specific. Also fixes a minor bug: CustomerIO.request() was not setting the User-Agent header on DELETE requests (nil body path).
joeybaer
approved these changes
May 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
CustomerIO.request()andAPIClient.doRequest()duplicated the same marshal → create request → set headers → execute → read body pipelinedoHTTP()inhttp.gothat accepts an auth callback; both clients delegate to itCustomerIO.request()was not setting User-Agent header on DELETE requests (nil body path)Test plan
go test -race ./...passesNote
Low Risk
Internal refactor with no public API changes; behavior is intended to stay the same aside from the User-Agent fix on nil-body Track requests.
Overview
Consolidates duplicated HTTP request logic from
CustomerIO.request()andAPIClient.doRequest()into a new shareddoHTTPhelper inhttp.go. Both clients now delegate marshaling, request construction,User-Agent, auth via a callerpreflighthook (Basic vs Bearer), execution, and body reads to that path while keeping their own status/error handling.Also fixes
CustomerIOrequests with a nil body (e.g. DELETE) soUser-Agentis set consistently, which the old nil-body branch skipped.Reviewed by Cursor Bugbot for commit ce5caeb. Bugbot is set up for automated code reviews on this repo. Configure here.