Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed content error when response is binary file #30

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

vincentwan
Copy link

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-io
Copy link

codecov-io commented Dec 19, 2018

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%) ⬆️

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.

@vincentwan
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants