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

Alexandre Julliard julliard at winehq.org
Fri Mar 4 09:39:34 CST 2011


Module: wine
Branch: master
Commit: 488c2d0c36bc4e0579f6aa54eb645fdf565b24fc
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=488c2d0c36bc4e0579f6aa54eb645fdf565b24fc

Author: Juan Lang <juan.lang at gmail.com>
Date:   Thu Mar  3 10:54:47 2011 -0800

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

---

 dlls/wininet/http.c |   70 ++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 64 insertions(+), 6 deletions(-)

diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c
index 649bd17..8787ba2 100644
--- a/dlls/wininet/http.c
+++ b/dlls/wininet/http.c
@@ -3761,16 +3761,74 @@ static void HTTP_ProcessExpires(http_request_t *request)
     BOOL expirationFound = FALSE;
     int headerIndex;
 
-    headerIndex = HTTP_GetCustomHeaderIndex(request, szExpires, 0, FALSE);
+    /* 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 expiresHeader = &request->custHeaders[headerIndex];
-        FILETIME ft;
+        LPHTTPHEADERW ccHeader = &request->custHeaders[headerIndex];
+        LPWSTR ptr;
 
-        if (HTTP_ParseDate(expiresHeader->lpszValue, &ft))
+        for (ptr = ccHeader->lpszValue; ptr && *ptr; )
         {
-            expirationFound = TRUE;
-            request->expires = ft;
+            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);
+        if (headerIndex != -1)
+        {
+            LPHTTPHEADERW expiresHeader = &request->custHeaders[headerIndex];
+            FILETIME ft;
+
+            if (HTTP_ParseDate(expiresHeader->lpszValue, &ft))
+            {
+                expirationFound = TRUE;
+                request->expires = ft;
+            }
         }
     }
     if (!expirationFound)




More information about the wine-cvs mailing list