https://github.com/appium/WebDriverAgent returns the response with header Content-Type: application/json;charset=UTF-8.
The body encode should be UTF-8, but /source endpoint by the appium/WebDriverAgent was detected as ASCII-8BIT by some http clients. appium/WebDriverAgent returns the XML body with NSUTF8StringEncoding. According to the documentation, the encoding is:
An 8-bit representation of Unicode characters, suitable for transmission or storage by ASCII-based systems.
So, probably these clients detect the response body as ASCII-8BIT, I assume. But the request by the appium/WebDriverAgent expects the encode type should be UTF-8 as the content type header, charset=UTF-8 header, so these clients should guess the body first.
So, like below:
uri = URI('http://localhost:8100/source')
res = Net::HTTP.get_response uri
res.body.encoding #=> #<Encoding:ASCII-8BIT>
res.body.force_encoding res.type_params['charset']
res.body.encoding #=> #<Encoding:UTF-8>
Btw, the response is JSON. So, Ruby can parse the body correctly as JSON with JSON.parse res.body. Then, the res.body.encoding also becomes #<Encoding:UTF-8>. This issue could happen only when clients get /source response directly by WebDriverAgent. (Not via Appium server)