django-rest-framework-proxy icon indicating copy to clipboard operation
django-rest-framework-proxy copied to clipboard

Fixed content error when response is binary file

Open vincentwan opened this issue 7 years ago • 2 comments

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.

vincentwan avatar Dec 19 '18 02:12 vincentwan

Codecov Report

Merging #30 into master will increase coverage by 0.88%. The diff coverage is 100%.

Impacted file tree graph

@@            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 data Powered by Codecov. Last update 1fa51b1...1084902. Read the comment docs.

codecov-io avatar Dec 19 '18 03:12 codecov-io

Hi @eofs could you please see if this is good to merge? Thanks!

vincentwan avatar Dec 21 '18 20:12 vincentwan