feat: supports custom client-side header configuration for API calls#113
feat: supports custom client-side header configuration for API calls#113chyroc merged 2 commits intocoze-dev:mainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds client-level default header merging to parseHeader in Changes
* The merge runs before request-specific headers are processed, so those can override these defaults. Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@request.go`:
- Around line 246-251: The current merge into r.Headers uses v[0] which can
panic if a header key has an empty slice (ins.headers[k] == nil or len==0), and
the merge order causes client-level headers to override per-request headers; fix
by first populating r.Headers with client defaults, then overlaying ins.headers
so request-level wins, and when iterating ins.headers (in the block using
ins.headers and r.Headers) check len(v) > 0 before reading v[0] (skip entries
with empty slices or handle them explicitly) to avoid panics; update the merge
logic that touches ins.headers and r.Headers accordingly.
When creating a custom CozeAPI client using the following code snippet, the custom headers fail to be included in the outgoing requests. This PR adds support for passing the custom headers (e.g., X-Use-Ppe, X-Tt-Env) to the actual HTTP requests sent by the CozeAPI client:
client = coze.NewCozeAPI(
coze.NewTokenAuth(cozeConf.CozeAPIToken),
coze.WithBaseURL(cozeBaseUrl),
coze.WithHttpClient(&http.Client{Timeout: 600 * time.Second}),
coze.WithHeaders(
http.Header{
"X-Use-Ppe": []string{"1"},
"X-Tt-Env": []string{os.Getenv("SERVICE_ENV")},
}))
Summary by CodeRabbit