diff options
Diffstat (limited to 'etc')
-rw-r--r-- | etc/cookie.lua | 22 | ||||
-rw-r--r-- | etc/get.lua | 2 |
2 files changed, 12 insertions, 12 deletions
diff --git a/etc/cookie.lua b/etc/cookie.lua index 4adb403..fec10a1 100644 --- a/etc/cookie.lua +++ b/etc/cookie.lua | |||
@@ -5,7 +5,7 @@ local ltn12 = require"ltn12" | |||
5 | 5 | ||
6 | local token_class = '[^%c%s%(%)%<%>%@%,%;%:%\\%"%/%[%]%?%=%{%}]' | 6 | local token_class = '[^%c%s%(%)%<%>%@%,%;%:%\\%"%/%[%]%?%=%{%}]' |
7 | 7 | ||
8 | local function unquote(t, quoted) | 8 | local function unquote(t, quoted) |
9 | local n = string.match(t, "%$(%d+)$") | 9 | local n = string.match(t, "%$(%d+)$") |
10 | if n then n = tonumber(n) end | 10 | if n then n = tonumber(n) end |
11 | if quoted[n] then return quoted[n] | 11 | if quoted[n] then return quoted[n] |
@@ -14,19 +14,19 @@ end | |||
14 | 14 | ||
15 | local function parse_set_cookie(c, quoted, cookie_table) | 15 | local function parse_set_cookie(c, quoted, cookie_table) |
16 | c = c .. ";$last=last;" | 16 | c = c .. ";$last=last;" |
17 | local _, __, n, v, i = string.find(c, "(" .. token_class .. | 17 | local _, _, n, v, i = string.find(c, "(" .. token_class .. |
18 | "+)%s*=%s*(.-)%s*;%s*()") | 18 | "+)%s*=%s*(.-)%s*;%s*()") |
19 | local cookie = { | 19 | local cookie = { |
20 | name = n, | 20 | name = n, |
21 | value = unquote(v, quoted), | 21 | value = unquote(v, quoted), |
22 | attributes = {} | 22 | attributes = {} |
23 | } | 23 | } |
24 | while 1 do | 24 | while 1 do |
25 | _, __, n, v, i = string.find(c, "(" .. token_class .. | 25 | _, _, n, v, i = string.find(c, "(" .. token_class .. |
26 | "+)%s*=?%s*(.-)%s*;%s*()", i) | 26 | "+)%s*=?%s*(.-)%s*;%s*()", i) |
27 | if not n or n == "$last" then break end | 27 | if not n or n == "$last" then break end |
28 | cookie.attributes[#cookie.attributes+1] = { | 28 | cookie.attributes[#cookie.attributes+1] = { |
29 | name = n, | 29 | name = n, |
30 | value = unquote(v, quoted) | 30 | value = unquote(v, quoted) |
31 | } | 31 | } |
32 | end | 32 | end |
@@ -46,8 +46,8 @@ local function split_set_cookie(s, cookie_table) | |||
46 | -- split into individual cookies | 46 | -- split into individual cookies |
47 | i = 1 | 47 | i = 1 |
48 | while 1 do | 48 | while 1 do |
49 | local _, __, cookie, next_token | 49 | local _, _, cookie, next_token |
50 | _, __, cookie, i, next_token = string.find(s, "(.-)%s*%,%s*()(" .. | 50 | _, _, cookie, i, next_token = string.find(s, "(.-)%s*%,%s*()(" .. |
51 | token_class .. "+)%s*=", i) | 51 | token_class .. "+)%s*=", i) |
52 | if not next_token then break end | 52 | if not next_token then break end |
53 | parse_set_cookie(cookie, quoted, cookie_table) | 53 | parse_set_cookie(cookie, quoted, cookie_table) |
@@ -62,12 +62,12 @@ local function quote(s) | |||
62 | end | 62 | end |
63 | 63 | ||
64 | local _empty = {} | 64 | local _empty = {} |
65 | local function build_cookies(cookies) | 65 | local function build_cookies(cookies) |
66 | s = "" | 66 | s = "" |
67 | for i,v in ipairs(cookies or _empty) do | 67 | for i,v in ipairs(cookies or _empty) do |
68 | if v.name then | 68 | if v.name then |
69 | s = s .. v.name | 69 | s = s .. v.name |
70 | if v.value and v.value ~= "" then | 70 | if v.value and v.value ~= "" then |
71 | s = s .. '=' .. quote(v.value) | 71 | s = s .. '=' .. quote(v.value) |
72 | end | 72 | end |
73 | end | 73 | end |
@@ -83,6 +83,6 @@ local function build_cookies(cookies) | |||
83 | end | 83 | end |
84 | if i < #cookies then s = s .. ", " end | 84 | if i < #cookies then s = s .. ", " end |
85 | end | 85 | end |
86 | return s | 86 | return s |
87 | end | 87 | end |
88 | 88 | ||
diff --git a/etc/get.lua b/etc/get.lua index 9edc235..d53c465 100644 --- a/etc/get.lua +++ b/etc/get.lua | |||
@@ -71,7 +71,7 @@ function stats(size) | |||
71 | local current = socket.gettime() | 71 | local current = socket.gettime() |
72 | if chunk then | 72 | if chunk then |
73 | -- total bytes received | 73 | -- total bytes received |
74 | got = got + string.len(chunk) | 74 | got = got + string.len(chunk) |
75 | -- not enough time for estimate | 75 | -- not enough time for estimate |
76 | if current - last > 1 then | 76 | if current - last > 1 then |
77 | io.stderr:write("\r", gauge(got, current - start, size)) | 77 | io.stderr:write("\r", gauge(got, current - start, size)) |