Cookie Jar: allow setting cookies on "file" URLs.
* These are shared with HTTP cookies set for localhost. We probably want to split them apart later on, so cookies should store and check the protocol, additionally to the path and domain. * Fixes #10195.
This commit is contained in:
parent
dc6d2ef664
commit
f36e1414b7
@ -38,6 +38,13 @@ BNetworkCookie::BNetworkCookie(const char* name, const char* value,
|
||||
fValue = value;
|
||||
|
||||
SetDomain(url.Host());
|
||||
|
||||
if(url.Protocol() == "file" && url.Host().Length() == 0)
|
||||
{
|
||||
SetDomain("localhost");
|
||||
// make sure cookies set from a file:// URL are stored somewhere.
|
||||
}
|
||||
|
||||
SetPath(_DefaultPathForUrl(url));
|
||||
}
|
||||
|
||||
@ -93,6 +100,13 @@ BNetworkCookie::ParseCookieString(const BString& string, const BUrl& url)
|
||||
SetPath(_DefaultPathForUrl(url));
|
||||
SetDomain(url.Host());
|
||||
fHostOnly = true;
|
||||
if(url.Protocol() == "file" && url.Host().Length() == 0)
|
||||
{
|
||||
fDomain = "localhost";
|
||||
// make sure cookies set from a file:// URL are stored somewhere.
|
||||
// not going through SetDomain as it requires at least one '.'
|
||||
// in the domain (to avoid setting cookies on TLDs).
|
||||
}
|
||||
|
||||
BString name;
|
||||
BString value;
|
||||
@ -166,13 +180,12 @@ BNetworkCookie::ParseCookieString(const BString& string, const BUrl& url)
|
||||
}
|
||||
}
|
||||
|
||||
if (!IsValidForDomain(url.Host())) {
|
||||
if (!IsValidForUrl(url)) {
|
||||
// Invalidate the cookie.
|
||||
_Reset();
|
||||
return B_NOT_ALLOWED;
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -423,6 +436,9 @@ BNetworkCookie::IsValidForUrl(const BUrl& url) const
|
||||
if (Secure() && url.Protocol() != "https")
|
||||
return false;
|
||||
|
||||
if (url.Protocol() == "file")
|
||||
return Domain() == "localhost" && IsValidForPath(url.Path());
|
||||
|
||||
return IsValidForDomain(url.Host()) && IsValidForPath(url.Path());
|
||||
}
|
||||
|
||||
|
@ -591,8 +591,12 @@ BNetworkCookieJar::UrlIterator::UrlIterator(const BNetworkCookieJar* cookieJar,
|
||||
{
|
||||
BString domain = url.Host();
|
||||
|
||||
if (!domain.Length())
|
||||
return;
|
||||
if (!domain.Length()) {
|
||||
if (url.Protocol() == "file")
|
||||
domain = "localhost";
|
||||
else
|
||||
return;
|
||||
}
|
||||
|
||||
fIterator = new(std::nothrow) PrivateIterator(
|
||||
fCookieJar->fCookieHashMap->fHashMap.GetIterator());
|
||||
|
Loading…
Reference in New Issue
Block a user