wininet: Added beginning support for HTTP cache files.
diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c
index 964140e..d718eea 100644
--- a/dlls/wininet/http.c
+++ b/dlls/wininet/http.c
@@ -2283,6 +2283,20 @@
return result;
}
+static BOOL HTTP_GetRequestURL(WININETHTTPREQW *req, LPWSTR buf)
+{
+ LPHTTPHEADERW host_header;
+
+ static const WCHAR formatW[] = {'h','t','t','p',':','/','/','%','s','%','s',0};
+
+ host_header = HTTP_GetHeader(req, szHost);
+ if(!host_header)
+ return FALSE;
+
+ sprintfW(buf, formatW, host_header->lpszValue, req->lpszPath); /* FIXME */
+ return TRUE;
+}
+
/***********************************************************************
* HTTP_HandleRedirect (internal)
*/
@@ -2743,6 +2757,32 @@
}
while (loop_next);
+ /* FIXME: Better check, when we have to create the cache file */
+ if(bSuccess && (lpwhr->hdr.dwFlags & INTERNET_FLAG_NEED_FILE)) {
+ WCHAR url[INTERNET_MAX_URL_LENGTH];
+ WCHAR cacheFileName[MAX_PATH+1];
+ BOOL b;
+
+ b = HTTP_GetRequestURL(lpwhr, url);
+ if(!b) {
+ WARN("Could not get URL\n");
+ goto lend;
+ }
+
+ b = CreateUrlCacheEntryW(url, lpwhr->dwContentLength > 0 ? lpwhr->dwContentLength : 0, NULL, cacheFileName, 0);
+ if(b) {
+ lpwhr->lpszCacheFile = WININET_strdupW(cacheFileName);
+ lpwhr->hCacheFile = CreateFileW(lpwhr->lpszCacheFile, GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+ if(lpwhr->hCacheFile == INVALID_HANDLE_VALUE) {
+ WARN("Could not create file: %u\n", GetLastError());
+ lpwhr->hCacheFile = NULL;
+ }
+ }else {
+ WARN("Could not create cache entry: %08x\n", GetLastError());
+ }
+ }
+
lend:
HeapFree(GetProcessHeap(), 0, requestString);
@@ -3393,6 +3433,14 @@
TRACE("\n");
+ if(lpwhr->hCacheFile)
+ CloseHandle(lpwhr->hCacheFile);
+
+ if(lpwhr->lpszCacheFile) {
+ DeleteFileW(lpwhr->lpszCacheFile); /* FIXME */
+ HeapFree(GetProcessHeap(), 0, lpwhr->lpszCacheFile);
+ }
+
WININET_Release(&lpwhr->lpHttpSession->hdr);
HeapFree(GetProcessHeap(), 0, lpwhr->lpszPath);
diff --git a/dlls/wininet/internet.c b/dlls/wininet/internet.c
index 595a718..7f422da 100644
--- a/dlls/wininet/internet.c
+++ b/dlls/wininet/internet.c
@@ -1775,6 +1775,15 @@
{
lpwhr->dwContentRead += bytes_read;
*pdwNumOfBytesRead = bytes_read;
+
+ if(lpwhr->lpszCacheFile) {
+ BOOL res;
+
+ res = WriteFile(lpwhr->hCacheFile, lpBuffer, bytes_read, NULL, NULL);
+ if(!res)
+ WARN("WriteFile failed: %u\n", GetLastError());
+ }
+
if (!bytes_read && (lpwhr->dwContentRead == lpwhr->dwContentLength))
retval = HTTP_FinishedReading(lpwhr);
else
diff --git a/dlls/wininet/internet.h b/dlls/wininet/internet.h
index 0f283e1..b80de88 100644
--- a/dlls/wininet/internet.h
+++ b/dlls/wininet/internet.h
@@ -209,6 +209,8 @@
DWORD dwContentRead; /* bytes of the content read so far */
HTTPHEADERW *pCustHeaders;
DWORD nCustHeaders;
+ HANDLE hCacheFile;
+ LPWSTR lpszCacheFile;
struct HttpAuthInfo *pAuthInfo;
struct HttpAuthInfo *pProxyAuthInfo;
} WININETHTTPREQW, *LPWININETHTTPREQW;