wininet: Support the Cache-Control max-age directive for setting url cache entry expiration.

This commit is contained in:
Juan Lang 2011-03-03 10:54:47 -08:00 committed by Alexandre Julliard
parent 2d323430cb
commit 488c2d0c36
1 changed files with 64 additions and 6 deletions

View File

@ -3761,6 +3761,63 @@ static void HTTP_ProcessExpires(http_request_t *request)
BOOL expirationFound = FALSE; BOOL expirationFound = FALSE;
int headerIndex; int headerIndex;
/* Look for a Cache-Control header with a max-age directive, as it takes
* precedence over the Expires header.
*/
headerIndex = HTTP_GetCustomHeaderIndex(request, szCache_Control, 0, FALSE);
if (headerIndex != -1)
{
LPHTTPHEADERW ccHeader = &request->custHeaders[headerIndex];
LPWSTR ptr;
for (ptr = ccHeader->lpszValue; ptr && *ptr; )
{
LPWSTR comma = strchrW(ptr, ','), end, equal;
if (comma)
end = comma;
else
end = ptr + strlenW(ptr);
for (equal = end - 1; equal > ptr && *equal != '='; equal--)
;
if (*equal == '=')
{
static const WCHAR max_age[] = {
'm','a','x','-','a','g','e',0 };
if (!strncmpiW(ptr, max_age, equal - ptr - 1))
{
LPWSTR nextPtr;
unsigned long age;
age = strtoulW(equal + 1, &nextPtr, 10);
if (nextPtr > equal + 1)
{
LARGE_INTEGER ft;
NtQuerySystemTime( &ft );
/* Age is in seconds, FILETIME resolution is in
* 100 nanosecond intervals.
*/
ft.QuadPart += age * (ULONGLONG)1000000;
request->expires.dwLowDateTime = ft.u.LowPart;
request->expires.dwHighDateTime = ft.u.HighPart;
expirationFound = TRUE;
}
}
}
if (comma)
{
ptr = comma + 1;
while (isspaceW(*ptr))
ptr++;
}
else
ptr = NULL;
}
}
if (!expirationFound)
{
headerIndex = HTTP_GetCustomHeaderIndex(request, szExpires, 0, FALSE); headerIndex = HTTP_GetCustomHeaderIndex(request, szExpires, 0, FALSE);
if (headerIndex != -1) if (headerIndex != -1)
{ {
@ -3773,6 +3830,7 @@ static void HTTP_ProcessExpires(http_request_t *request)
request->expires = ft; request->expires = ft;
} }
} }
}
if (!expirationFound) if (!expirationFound)
{ {
LARGE_INTEGER t; LARGE_INTEGER t;