gist-logs: fix up encoding before passing the response body to OkJson
Fixes Homebrew/homebrew#30519.
This commit is contained in:
parent
7cd31377a4
commit
6b5c53b03f
@ -76,7 +76,14 @@ def post path, data
|
||||
request.body = Utils::JSON.dump(data)
|
||||
response = http.request(request)
|
||||
raise HTTP_Error, response if response.code != '201'
|
||||
Utils::JSON.load(response.body)
|
||||
|
||||
if response["Content-Type"].downcase == "application/json; charset=utf-8"
|
||||
body = response.body.dup.force_encoding(Encoding::UTF_8)
|
||||
else
|
||||
body = response.body.encode(Encoding::UTF_8, undef: :replace)
|
||||
end
|
||||
|
||||
Utils::JSON.load(body)
|
||||
end
|
||||
|
||||
class HTTP_Error < RuntimeError
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user