Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Commit

Permalink
fix: http handler not handling unicode gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanctech committed Aug 20, 2020
1 parent e299599 commit 096ee15
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 9 deletions.
6 changes: 4 additions & 2 deletions sonorancad/core/http.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
function byteCount(s) {
return encodeURI(s).split(/%..|./).length - 1;
}

//url, cb, method, data, headers
exports('HandleHttpRequest', (dest, callback, method, data, headers) => {
const urlObj = url.parse(dest)
const options = {
Expand All @@ -10,7 +12,7 @@ exports('HandleHttpRequest', (dest, callback, method, data, headers) => {
}
if (method == "POST") {
options.headers['Content-Type'] = 'application/json',
options.headers['Content-Length'] = data.length
options.headers['Content-Length'] = byteCount(data)
}
else if (method != "GET") {
console.error("Invalid request. Only GET/POST supported. Method: " + method);
Expand Down
4 changes: 2 additions & 2 deletions sonorancad/core/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ function performApiRequest(postData, type, cb)
apiUrl = "https://api.sonoransoftware.com/"
end
PerformHttpRequest(apiUrl..tostring(endpoint), function(statusCode, res, headers)
debugPrint(("type %s called with post data %s to url %s"):format(type, json.encode(payload), Config.apiUrl..tostring(endpoint)))
--debugPrint(("type %s called with post data %s to url %s"):format(type, json.encode(payload), Config.apiUrl..tostring(endpoint)))
if statusCode == 200 and res ~= nil then
debugPrint("result: "..tostring(res))
--debugPrint("result: "..tostring(res))
cb(res, true)
elseif statusCode == 404 then -- handle 404 requests, like from CHECK_APIID
cb(res, false)
Expand Down
2 changes: 1 addition & 1 deletion sonorancad/plugins/apicheck
2 changes: 1 addition & 1 deletion sonorancad/plugins/livemap
2 changes: 1 addition & 1 deletion sonorancad/plugins/lookups
2 changes: 1 addition & 1 deletion sonorancad/plugins/pushevents
2 changes: 1 addition & 1 deletion sonorancad/plugins/wraithv2

0 comments on commit 096ee15

Please sign in to comment.