@@ -15,7 +15,6 @@ local config = require("rest-nvim.config")
15
15
--- @field domain string
16
16
--- @field path string
17
17
--- @field expires integer
18
- --- @field max_date integer ?
19
18
--- @field secure boolean ?
20
19
--- @field httponly boolean ?
21
20
--- @field samesite string ?
61
60
--- @return string domain
62
61
--- @return string path
63
62
local function parse_url (url )
64
- local domain , path = url :match (" ^https? ://([^/]+)(/[^?#]*)$" )
63
+ local domain , path = url :match (" ^%a+ ://([^/]+)(/[^?#]*)$" )
65
64
if not path then
66
- domain = url :match (" ^https? ://([^/]+)" )
65
+ domain = url :match (" ^%a+ ://([^/]+)" )
67
66
path = " /"
68
67
end
69
68
return domain , path
@@ -80,10 +79,12 @@ function M.parse_set_cookie(req_url, header)
80
79
logger .error (" Invalid Set-Cookie header: " .. header )
81
80
return
82
81
end
82
+ logger .debug (" parsing set-cookie:" , name , value )
83
83
local cookie = {
84
84
name = name ,
85
85
value = value or " " ,
86
86
}
87
+ local max_age
87
88
for attr , val in header :gmatch (" ;%s*([^=]+)=?([^;]*)" ) do
88
89
attr = attr :lower ()
89
90
if attr == " domain" then
@@ -93,7 +94,7 @@ function M.parse_set_cookie(req_url, header)
93
94
elseif attr == " expires" then
94
95
cookie .expires = utils .parse_http_time (val )
95
96
elseif attr == " max-age" then
96
- cookie . max_age = tonumber (val )
97
+ max_age = tonumber (val )
97
98
elseif attr == " secure" then
98
99
cookie .secure = true
99
100
elseif attr == " httponly" then
@@ -104,10 +105,15 @@ function M.parse_set_cookie(req_url, header)
104
105
cookie .priority = val
105
106
end
106
107
end
107
- cookie .domain = cookie .domain or req_url :match (" ^https?://([^/]+)" )
108
- cookie .domain = " ." .. cookie .domain
108
+ cookie .domain = cookie .domain or (" ." .. req_url :match (" ^%a+://([^/]+)" ))
109
109
cookie .path = cookie .path or " /"
110
+ if max_age == - 1 then
111
+ cookie .expires = - 1
112
+ elseif max_age then
113
+ cookie .expires = os.time () + max_age
114
+ end
110
115
cookie .expires = cookie .expires or - 1
116
+ logger .debug (" cookie parsed from Set-Cookie Header:" , cookie )
111
117
return cookie
112
118
end
113
119
149
155
function M .clean ()
150
156
M .jar = vim .iter (M .jar )
151
157
:filter (function (cookie )
152
- return cookie .max_age == 0 or cookie .expires < os.time ()
158
+ return cookie .expires == - 1 or cookie .expires > os.time ()
153
159
end )
154
160
:totable ()
155
161
end
0 commit comments