feat: auto deduce content type when requesting data#49
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #49 +/- ##
==========================================
+ Coverage 80.19% 83.05% +2.85%
==========================================
Files 7 7
Lines 409 360 -49
==========================================
- Hits 328 299 -29
+ Misses 59 38 -21
- Partials 22 23 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| // Data sets data of request body. It also deduces and sets the Content-Type | ||
| // for the input data. |
There was a problem hiding this comment.
Add more details for deducing different content types based on data types:
- "application/json": struct, slice(except []byte), and map
- auto deduce by [http.DetectContentType]: []byte, io.Reader
- "text/plain": others
| default: | ||
| return plainTextType, fmt.Appendf(nil, "%v", bodyValue.Interface()), nil |
There was a problem hiding this comment.
If the data type is io.Reader, we should also process it well. just like: https://github.com/go-resty/resty/blob/v3/middleware.go#L428C7-L428C16
There was a problem hiding this comment.
Done. We check if the input data implements io.Reader first before checking its reflect.Kind.
Code reviewFound 2 issues:
Lines 189 to 199 in c6790f3
Lines 189 to 202 in c6790f3 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
- Use the dereferenced reflect.Value for the []byte assertion so that *[]byte is treated as raw bytes (http.DetectContentType) instead of being JSON/base64-marshaled. - Guard against invalid reflect.Value from typed nil pointers (e.g. (*T)(nil)) to avoid panicking on bodyValue.Interface(). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Uh oh!
There was an error while loading. Please reload this page.