It's far from perfect. The current bug appears to be down to a longstanding quirk in Ruby's Net::HTTP handler that means it interprets whatever it's given as ASCII. 

Having another look. It might be that a safer fix will involve altering the receiving API as well.