HTTPS support for download_to_file 🔒 and string:starts(text) function
This commit is contained in:
parent
13a787e577
commit
6a8be34956
@ -69,9 +69,21 @@ function download_to_file(url, file_name)
|
|||||||
redirect = true
|
redirect = true
|
||||||
}
|
}
|
||||||
|
|
||||||
local one, c, h = http.request(options)
|
-- nil, code, headers, status
|
||||||
|
local response = nil
|
||||||
|
|
||||||
file_name = file_name or get_http_file_name(url, h)
|
if url:starts('https') then
|
||||||
|
options.redirect = false
|
||||||
|
response = {https.request(options)}
|
||||||
|
else
|
||||||
|
response = {http.request(options)}
|
||||||
|
end
|
||||||
|
|
||||||
|
local code = response[2]
|
||||||
|
local headers = response[3]
|
||||||
|
local status = response[4]
|
||||||
|
|
||||||
|
file_name = file_name or get_http_file_name(url, headers)
|
||||||
|
|
||||||
local file_path = "/tmp/"..file_name
|
local file_path = "/tmp/"..file_name
|
||||||
print("Saved to: "..file_path)
|
print("Saved to: "..file_path)
|
||||||
@ -204,11 +216,17 @@ function string:isblank()
|
|||||||
return self:isempty()
|
return self:isempty()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Returns true if String starts with Start
|
-- DEPRECATED!!!!!
|
||||||
function string.starts(String, Start)
|
function string.starts(String, Start)
|
||||||
|
print "string.starts(String, Start) is DEPRECATED use string:starts(text) instead"
|
||||||
return Start == string.sub(String,1,string.len(Start))
|
return Start == string.sub(String,1,string.len(Start))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Returns true if String starts with Start
|
||||||
|
function string:starts(text)
|
||||||
|
return text == string.sub(self,1,string.len(text))
|
||||||
|
end
|
||||||
|
|
||||||
-- Send image to user and delete it when finished.
|
-- Send image to user and delete it when finished.
|
||||||
-- cb_function and cb_extra are optionals callback
|
-- cb_function and cb_extra are optionals callback
|
||||||
function _send_photo(receiver, file_path, cb_function, cb_extra)
|
function _send_photo(receiver, file_path, cb_function, cb_extra)
|
||||||
|
Reference in New Issue
Block a user