mirror of
https://github.com/samsonjs/http-cookie.git
synced 2026-03-25 08:55:53 +00:00
Merge branch 'fix_time_representation'
This commit is contained in:
commit
80e855fdf2
1 changed files with 15 additions and 7 deletions
|
|
@ -357,8 +357,8 @@ class HTTP::CookieJar
|
||||||
:host => cookie.dot_domain,
|
:host => cookie.dot_domain,
|
||||||
:path => cookie.path,
|
:path => cookie.path,
|
||||||
:expiry => cookie.expires_at.to_i,
|
:expiry => cookie.expires_at.to_i,
|
||||||
:creationTime => cookie.created_at.to_i,
|
:creationTime => serialize_usectime(cookie.created_at),
|
||||||
:lastAccessed => cookie.accessed_at.to_i,
|
:lastAccessed => serialize_usectime(cookie.accessed_at),
|
||||||
:isSecure => cookie.secure? ? 1 : 0,
|
:isSecure => cookie.secure? ? 1 : 0,
|
||||||
:isHttpOnly => cookie.httponly? ? 1 : 0,
|
:isHttpOnly => cookie.httponly? ? 1 : 0,
|
||||||
:appId => @app_id,
|
:appId => @app_id,
|
||||||
|
|
@ -411,6 +411,14 @@ class HTTP::CookieJar
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def serialize_usectime(time)
|
||||||
|
time ? (time.to_f * 1e6).floor : 0
|
||||||
|
end
|
||||||
|
|
||||||
|
def deserialize_usectime(value)
|
||||||
|
Time.at(value ? value / 1e6 : 0)
|
||||||
|
end
|
||||||
|
|
||||||
public
|
public
|
||||||
|
|
||||||
def add(cookie)
|
def add(cookie)
|
||||||
|
|
@ -470,8 +478,8 @@ class HTTP::CookieJar
|
||||||
attrs[:domain] = row['host']
|
attrs[:domain] = row['host']
|
||||||
attrs[:path] = row['path']
|
attrs[:path] = row['path']
|
||||||
attrs[:expires_at] = Time.at(row['expiry'])
|
attrs[:expires_at] = Time.at(row['expiry'])
|
||||||
attrs[:accessed_at] = Time.at(row['lastAccessed'] || 0)
|
attrs[:accessed_at] = deserialize_usectime(row['lastAccessed'])
|
||||||
attrs[:created_at] = Time.at(row['creationTime'] || 0)
|
attrs[:created_at] = deserialize_usectime(row['creationTime'])
|
||||||
attrs[:secure] = secure
|
attrs[:secure] = secure
|
||||||
attrs[:httponly] = row['isHttpOnly'] != 0
|
attrs[:httponly] = row['isHttpOnly'] != 0
|
||||||
})
|
})
|
||||||
|
|
@ -479,7 +487,7 @@ class HTTP::CookieJar
|
||||||
if cookie.valid_for_uri?(uri)
|
if cookie.valid_for_uri?(uri)
|
||||||
cookie.accessed_at = now
|
cookie.accessed_at = now
|
||||||
@stmt[:update_lastaccessed].execute({
|
@stmt[:update_lastaccessed].execute({
|
||||||
'lastAccessed' => now.to_i,
|
'lastAccessed' => serialize_usectime(now),
|
||||||
'id' => row['id'],
|
'id' => row['id'],
|
||||||
})
|
})
|
||||||
yield cookie
|
yield cookie
|
||||||
|
|
@ -498,8 +506,8 @@ class HTTP::CookieJar
|
||||||
attrs[:domain] = row['host']
|
attrs[:domain] = row['host']
|
||||||
attrs[:path] = row['path']
|
attrs[:path] = row['path']
|
||||||
attrs[:expires_at] = Time.at(row['expiry'])
|
attrs[:expires_at] = Time.at(row['expiry'])
|
||||||
attrs[:accessed_at] = Time.at(row['lastAccessed'] || 0)
|
attrs[:accessed_at] = deserialize_usectime(row['lastAccessed'])
|
||||||
attrs[:created_at] = Time.at(row['creationTime'] || 0)
|
attrs[:created_at] = deserialize_usectime(row['creationTime'])
|
||||||
attrs[:secure] = row['isSecure'] != 0
|
attrs[:secure] = row['isSecure'] != 0
|
||||||
attrs[:httponly] = row['isHttpOnly'] != 0
|
attrs[:httponly] = row['isHttpOnly'] != 0
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue