Comments (3)
I wrote some code to handle the charset (see below). I really have no idea how to write the tests, unfortunately. I haven't used RSpec before. I see a bunch of nested tests but I'm not sure how to stub responses inside an adapter test. Any pointers?
def encoded_body(http_response)
body = http_response.body || +''
if encoding = encoding_for(http_response)
if body.encoding != encoding
body = body.dup if body.frozen?
body.force_encoding(encoding)
end
end
body
end
def encoding_for(http_response)
if content_type = http_response['Content-Type']
if encoding = content_type[/\bcharset=\s*(.+?)\s*(;|$)/, 1]
Encoding.find(encoding) rescue nil
end
end
end
from faraday-net_http.
Also, I am unfamiliar with this syntax http_response.body || +''
. I copied it from the code above, but what does it do? :)
from faraday-net_http.
Hi @gurgeous thanks for raising this and doing some initial research!
We can take this from here and incorporate your code with some RSpec tests in a PR, I'll just need to find some time to work on it (@olleolleolle @JanDintel feel free to jump in if you have some time!).
Also, I am unfamiliar with this syntax
http_response.body || +''
. I copied it from the code above, but what does it do? :)
The only "strange" thing in there I can see is the +
prefix to the string literal, which makes the string mutable rather than the immutable default
That together with body = body.dup if body.frozen?
is necessary to be able to call force_encoding
later
from faraday-net_http.
Related Issues (10)
- Net::HTTP adapter trusts all system root CAs when a ca_file is specified HOT 5
- Error on send Certificate array chain in ssl HOT 6
- Conflicts with faraday-encoding HOT 1
- undefined method `idle_timeout=' for #<Net::HTTP :80 open=false> HOT 2
- Wrap Errno::EALREADY HOT 2
- Duplicate require warnings on Ruby 2.7.5 HOT 1
- Add explicit runtime dependency on faraday itself HOT 2
- Error class is different according to adapters HOT 3
- already initialized constant warnings HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from faraday-net_http.