http.c: redirect corrections.

Aric Stewart aric at codeweavers.com
Tue Nov 22 09:42:43 CST 2005


Allow HttpEndRequest to process 302 and 301 redirects.  Append Host port 
if non standard on the redirect host header and make sure to append the 
extra information (parameters) and such to the location if present.
additionally check to see if we are redirecting to https and if so set 
the approperate port.
-------------- next part --------------
Index: dlls/wininet/http.c
===================================================================
RCS file: /home/wine/wine/dlls/wininet/http.c,v
retrieving revision 1.113
diff -u -r1.113 http.c
--- dlls/wininet/http.c	22 Nov 2005 14:53:30 -0000	1.113
+++ dlls/wininet/http.c	22 Nov 2005 15:35:24 -0000
@@ -95,7 +95,12 @@
 static LPWSTR HTTP_build_req( LPCWSTR *list, int len );
 static BOOL HTTP_InsertProxyAuthorization( LPWININETHTTPREQW lpwhr,
                        LPCWSTR username, LPCWSTR password );
-
+static BOOL WINAPI HTTP_HttpQueryInfoW( LPWININETHTTPREQW lpwhr, DWORD
+        dwInfoLevel, LPVOID lpBuffer, LPDWORD lpdwBufferLength, LPDWORD
+        lpdwIndex);
+static BOOL HTTP_HandleRedirect(LPWININETHTTPREQW lpwhr, LPCWSTR lpszUrl,
+        LPCWSTR lpszHeaders, DWORD dwHeaderLength, LPVOID lpOptional, DWORD
+        dwOptionalLength);
 
 /***********************************************************************
  *           HTTP_Tokenize (internal)
@@ -629,6 +634,26 @@
 
     /* We appear to do nothing with the buffer.. is that correct? */
 
+    if(!(lpwhr->hdr.dwFlags & INTERNET_FLAG_NO_AUTO_REDIRECT))
+    {
+        DWORD dwCode,dwCodeLength=sizeof(DWORD),dwIndex=0;
+        if(HTTP_HttpQueryInfoW(lpwhr,HTTP_QUERY_FLAG_NUMBER|HTTP_QUERY_STATUS_CODE,&dwCode,&dwCodeLength,&dwIndex) &&
+            (dwCode==302 || dwCode==301))
+        {
+            WCHAR szNewLocation[2048];
+            DWORD dwBufferSize=2048;
+            dwIndex=0;
+            if(HTTP_HttpQueryInfoW(lpwhr,HTTP_QUERY_LOCATION,szNewLocation,&dwBufferSize,&dwIndex))
+            {
+	            static const WCHAR szGET[] = { 'G','E','T', 0 };
+                /* redirects are always GETs */
+                HeapFree(GetProcessHeap(),0,lpwhr->lpszVerb);
+	            lpwhr->lpszVerb = WININET_strdupW(szGET);
+                return HTTP_HandleRedirect(lpwhr, szNewLocation, NULL, 0, NULL, 0);
+            }
+        }
+    }
+
     TRACE("%i <--\n",rc);
     return rc;
 }
@@ -1812,6 +1837,12 @@
         URL_COMPONENTSW urlComponents;
         WCHAR protocol[32], hostName[MAXHOSTNAME], userName[1024];
         WCHAR password[1024], extra[1024];
+        memset(extra,0,sizeof(extra));
+        memset(password,0,sizeof(password));
+        memset(userName,0,sizeof(userName));
+        memset(hostName,0,sizeof(hostName));
+        memset(protocol,0,sizeof(protocol));
+
         urlComponents.dwStructSize = sizeof(URL_COMPONENTSW);
         urlComponents.lpszScheme = protocol;
         urlComponents.dwSchemeLength = 32;
@@ -1829,7 +1860,12 @@
             return FALSE;
         
         if (urlComponents.nPort == INTERNET_INVALID_PORT_NUMBER)
-            urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
+        {
+            if (lstrlenW(protocol)>4) /*https*/
+                urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT;
+            else /*http*/
+                urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT;
+        }
 
 #if 0
         /*
@@ -1849,13 +1885,26 @@
 #endif
         
         HeapFree(GetProcessHeap(), 0, lpwhs->lpszServerName);
-        lpwhs->lpszServerName = WININET_strdupW(hostName);
+        if (urlComponents.nPort != INTERNET_DEFAULT_HTTP_PORT &&
+                urlComponents.nPort != INTERNET_DEFAULT_HTTPS_PORT)
+        {
+            int len;
+            static WCHAR fmt[] = {'%','s',':','%','i',0};
+            len = lstrlenW(hostName);
+            len+=6;
+            lpwhs->lpszServerName = HeapAlloc(GetProcessHeap(),0,len*sizeof(WCHAR));
+            sprintfW(lpwhs->lpszServerName,fmt,hostName,urlComponents.nPort);
+        }
+        else
+            lpwhs->lpszServerName = WININET_strdupW(hostName);
+
+        HTTP_ProcessHeader(lpwhr, g_szHost, lpwhs->lpszServerName, HTTP_ADDREQ_FLAG_ADD | HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDHDR_FLAG_REQ);
+
+        
         HeapFree(GetProcessHeap(), 0, lpwhs->lpszUserName);
         lpwhs->lpszUserName = WININET_strdupW(userName);
         lpwhs->nServerPort = urlComponents.nPort;
 
-        HTTP_ProcessHeader(lpwhr, g_szHost, hostName, HTTP_ADDREQ_FLAG_ADD | HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDHDR_FLAG_REQ);
-
         SendAsyncCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
                       INTERNET_STATUS_RESOLVING_NAME,
                       lpwhs->lpszServerName,
@@ -1868,6 +1917,9 @@
             return FALSE;
         }
 
+        if (lstrlenW(extra)>0)
+            StrCatW(path,extra);
+
         SendAsyncCallback(&lpwhr->hdr, lpwhr->hdr.dwContext,
                       INTERNET_STATUS_NAME_RESOLVED,
                       &(lpwhs->socketAddress),


More information about the wine-patches mailing list