igrigorik / em-http-request

Asynchronous HTTP Client (EventMachine + Ruby)
1.22k stars 222 forks source link

Response is being truncated when it includes multibyte chars #320

Closed ryan-plated closed 5 years ago

ryan-plated commented 6 years ago

it appears bytesize returns the wrong length

https://github.com/igrigorik/em-http-request/blob/bcba7b6e80ef9c211c7d56c90ab91a232fa6e212/lib/em-http/client.rb#L185

https://github.com/oesmith/puffing-billy/issues/233

igrigorik commented 6 years ago

Thanks for reporting this. Do you have an example where this fails for em-http? The thread you linked to talks about Chrome receiving the response.. it's unclear to where if/where em-http is involved there.

nicedawg commented 6 years ago

I found this reported issue while looking into oesmith/puffing-billy#193 -- specifically the problem the described in this comment, and the subsequent discussion.

My primitive understanding of the puffing-billy code is that it makes a request (acting as a proxy on behalf of a browser like chrome), ultimately using EventMachine::HttpRequest to send the request and getting the response from EventMachine::HttpClient. (I could be misunderstanding it, though.)

In this comment somebody created a simple reproduction of the issue I'm interested in.

Of course, this may not help with oesmith/puffing-billy#233, but I hope it at least sheds (correct) light on how puffing-billy uses em-http-request.

igrigorik commented 6 years ago

@nicedawg hmm, thanks for the link. On first pass, I don't think these two issues are related. It's also not clear to me if em-http is the culprit in that thread, but that's a different discussion.

@ryan-plated per your earlier comment...

require 'json'

hash = { localidade: 'Niterói', bairro: 'Icaraí' }
json = JSON.generate(hash)

puts json
puts json.bytesize

ruby test.rb {"localidade":"Niterói","bairro":"Icaraí"} 44

That looks correct to me. Assuming the payload is not being converted to some other encoding before it's passed to em-http, bytesize should do return the right value?

hawkins commented 5 years ago

The original puffing-billy issue which sparked this issue has since been closed with a workaround that doesn't even point to a change in this repo. Is there still an underlying issue with EM HTTP and multibyte character codes?

ryan-plated commented 5 years ago

I think it is fine to close the comment now. I haven't run in to it recently, Thanks for following up.