forked from premake/premake-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp.lua
More file actions
68 lines (59 loc) · 1.27 KB
/
http.lua
File metadata and controls
68 lines (59 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
--
-- http.lua
-- Additions to the http namespace.
-- Copyright (c) 2008-2014 Jason Perkins and the Premake project
--
if http == nil then
return
end
---
-- Simple progress bar on stdout for curl downloads.
---
function http.reportProgress(total, current)
local width = 70
local progress = math.floor(current * width / total)
if progress == width then
io.write(string.rep(' ', width + 2) .. '\r')
else
io.write('[' .. string.rep('=', progress) .. string.rep(' ', width - progress) .. ']\r')
end
end
---
-- Correctly escape parameters for use in a url.
---
function http.escapeUrlParam(param)
local url_encodings = {
[' '] = '%%20',
['!'] = '%%21',
['"'] = '%%22',
['#'] = '%%23',
['$'] = '%%24',
['&'] = '%%26',
['\''] = '%%27',
['('] = '%%28',
[')'] = '%%29',
['*'] = '%%2A',
['+'] = '%%2B',
['-'] = '%%2D',
['.'] = '%%2E',
['/'] = '%%2F',
[':'] = '%%3A',
[';'] = '%%3B',
['<'] = '%%3C',
['='] = '%%3D',
['>'] = '%%3E',
['?'] = '%%3F',
['@'] = '%%40',
['['] = '%%5B',
['\\'] = '%%5C',
[']'] = '%%5D',
['^'] = '%%5E',
['_'] = '%%5F',
['`'] = '%%60'
}
param = param:gsub('%%', '%%25')
for k,v in pairs(url_encodings) do
param = param:gsub('%' .. k, v)
end
return param
end