Fixed content error when response is binary file
With return_raw set to true, I got wrong content in the response data when trying to proxy an API that returns an mp3 file.
Seems that we are using the response.text field even for binary content. And what happens inside response.text is:
content = str(self.content, errors='replace')
And then we encode the result string with utf-8.
Fixed that by setting the content field instead in the HttpResponse.
A test case for the return raw case is provided.
Codecov Report
Merging #30 into master will increase coverage by
0.88%. The diff coverage is100%.
@@ Coverage Diff @@
## master #30 +/- ##
==========================================
+ Coverage 67.55% 68.44% +0.88%
==========================================
Files 5 5
Lines 225 225
==========================================
+ Hits 152 154 +2
+ Misses 73 71 -2
| Impacted Files | Coverage Δ | |
|---|---|---|
| rest_framework_proxy/views.py | 72.59% <100%> (+1.48%) |
:arrow_up: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update 1fa51b1...1084902. Read the comment docs.
Hi @eofs could you please see if this is good to merge? Thanks!